Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,42 @@
|
|||
const std = @import("std");
|
||||
|
||||
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
||||
|
||||
const allocator = arena.allocator();
|
||||
|
||||
pub fn LinkedList(comptime Value: type) type {
|
||||
return struct {
|
||||
const This = @This();
|
||||
|
||||
const Node = struct {
|
||||
value: Value,
|
||||
next: ?*Node,
|
||||
};
|
||||
|
||||
head: ?*Node,
|
||||
tail: ?*Node,
|
||||
|
||||
pub fn init() This {
|
||||
return LinkedList(Value) {
|
||||
.head = null,
|
||||
.tail = null,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn add(this: *This, value: Value) !void {
|
||||
var newNode = try allocator.create(Node);
|
||||
|
||||
newNode.* = .{ .value = value, .next = null };
|
||||
|
||||
if (this.tail) |tail| {
|
||||
tail.next = newNode;
|
||||
this.tail = newNode;
|
||||
} else if (this.head) |head| {
|
||||
head.next = newNode;
|
||||
this.tail = newNode;
|
||||
} else {
|
||||
this.head = newNode;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
var l1 = LinkedList(i32).init();
|
||||
|
|
@ -0,0 +1 @@
|
|||
try list.add(1);
|
||||
Loading…
Add table
Add a link
Reference in a new issue