LinkedList implemented
This commit is contained in:
parent
b7ee15f76a
commit
e91c744c16
@ -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;
|
||||
var elem: ?*Node = undefined;
|
||||
|
||||
if (self.current == null) {
|
||||
elem = self.head;
|
||||
self.current = self.head.?.next;
|
||||
} else {
|
||||
current = self.head;
|
||||
self.current = self.head;
|
||||
elem = self.current;
|
||||
self.current = self.current.?.next;
|
||||
}
|
||||
return elem.?.point;
|
||||
}
|
||||
|
||||
return current.?.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 {
|
||||
|
Loading…
Reference in New Issue
Block a user