| ... | ... | @@ -62,7 +62,7 @@ pub fn SinglyLinkedList(comptime T: type) type { |
| 62 | 62 | /// This operation is O(N). |
| 63 | 63 | pub fn countChildren(node: *const Node) usize { |
| 64 | 64 | var count: usize = 0; |
| 65 | | var it: ?*const Node = node; |
| 65 | var it: ?*const Node = node.next; |
| 66 | 66 | while (it) |n| : (it = n.next) { |
| 67 | 67 | count += 1; |
| 68 | 68 | } |
| ... | ... | @@ -123,6 +123,8 @@ test "basic SinglyLinkedList test" { |
| 123 | 123 | const L = SinglyLinkedList(u32); |
| 124 | 124 | var list = L{}; |
| 125 | 125 | |
| 126 | testing.expect(list.len() == 0); |
| 127 | |
| 126 | 128 | var one = L.Node{ .data = 1 }; |
| 127 | 129 | var two = L.Node{ .data = 2 }; |
| 128 | 130 | var three = L.Node{ .data = 3 }; |
| ... | ... | @@ -135,6 +137,8 @@ test "basic SinglyLinkedList test" { |
| 135 | 137 | two.insertAfter(&three); // {1, 2, 3, 5} |
| 136 | 138 | three.insertAfter(&four); // {1, 2, 3, 4, 5} |
| 137 | 139 | |
| 140 | testing.expect(list.len() == 5); |
| 141 | |
| 138 | 142 | // Traverse forwards. |
| 139 | 143 | { |
| 140 | 144 | var it = list.first; |