PR3L-Verkettete-Listen-Abgabe2/LList.zig

45 lines
1.1 KiB
Zig
Raw Normal View History

const std = @import("std");
pub fn LLIst (comptime T: type) type {
return struct {
const Self = @This();
first: *Node(T),
//TODO Liste mit allen Nodes erstellen
pub fn init(this: *Self) !void {
//TODO Heap mit allocater nutzen
var node: Node(T) = undefined;
node.init(69);
try node.printNode();
this.first = &node;
}
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();
next: *Self, //? Nächste Node in der Liste
position: i64, //? Position der Node in der List, später übergeben mit zB List.len
value: T,
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 {
var testList: LLIst(u64) = undefined;
try testList.init();
}