046_optionals2.patch 634 B

1234567891011121314151617181920
  1. --- exercises/046_optionals2.zig 2023-10-03 22:15:22.122241138 +0200
  2. +++ answers/046_optionals2.zig 2023-10-05 20:04:07.049433424 +0200
  3. @@ -21,7 +21,7 @@
  4. const Elephant = struct {
  5. letter: u8,
  6. - tail: *Elephant = null, // Hmm... tail needs something...
  7. + tail: ?*Elephant = null, // <---- make this optional!
  8. visited: bool = false,
  9. };
  10. @@ -51,7 +51,7 @@
  11. // We should stop once we encounter a tail that
  12. // does NOT point to another element. What can
  13. // we put here to make that happen?
  14. - if (e.tail == null) ???;
  15. + if (e.tail == null) break;
  16. e = e.tail.?;
  17. }