PR3L-Verkettete-Listen-Abgabe2/LList.zig

39 lines
868 B
Zig
Raw Normal View History

const std = @import("std");
2024-11-08 20:26:58 +01:00
pub fn LList (comptime T: type) type {
return struct {
const Self = @This();
2024-11-08 20:26:58 +01:00
first: ?*Node(T),
pub fn init(this: *Self) !void { // ! allocator: *std.mem.allocator als zweiter Parameter
this.first = null;
}
pub fn deinit() void {
2024-11-06 15:46:19 +01:00
//TODO
}
};
}
pub fn Node (comptime T: type) type {
return struct {
const Self = @This();
2024-11-08 21:03:04 +01:00
next: ?*Self, //? Nächste Node in der Liste
pub fn init(this: *Self, value: T) void {
this.value = value;
}
pub fn printNode(this: *Self) !void {
const writer = std.io.getStdOut().writer();
try writer.print("Value: {any} \n", .{this.value});
}
};
}
pub fn main() !void {
2024-11-08 21:03:04 +01:00
var testList: LList(u64) = undefined;
try testList.init();
}