From e91c744c16ff969f88a333270355011050e1573b Mon Sep 17 00:00:00 2001 From: jonathan santis Date: Fri, 1 Nov 2024 11:34:24 +0100 Subject: [PATCH] LinkedList implemented --- primitives.zig | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/primitives.zig b/primitives.zig index 6e4e3a0..42ec7aa 100644 --- a/primitives.zig +++ b/primitives.zig @@ -56,17 +56,18 @@ pub fn LinkedList() type { self.length += 1; } pub fn next(self: *Self) Point { - var current: ?*Node = undefined; - if (self.current != null) { - current = self.current; - self.current = self.current.?.next; - } else { - current = self.head; - self.current = self.head; - } + var elem: ?*Node = undefined; - return current.?.point; + if (self.current == null) { + elem = self.head; + self.current = self.head.?.next; + } else { + elem = self.current; + self.current = self.current.?.next; + } + return elem.?.point; } + pub fn dump(self: *Self) ![]Point { const allocator = self.allocator; var node = self.head; @@ -101,25 +102,10 @@ test "test linked list" { const points: []Point = try polygon.dump(); for (points) |point| { - std.debug.print("x:{}\n", .{point.x}); - std.debug.print("y:{}\n", .{point.y}); - std.debug.print("z:{}\n", .{point.z}); + std.debug.print("Point dump:{}\n", .{point}); } std.debug.print("next:{}\n", .{polygon.next()}); std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); } pub fn pixel(buffer: []u8, w: Winsize, x: i64, y: i64, symbol: u21) !void {