mirror of
https://github.com/krahets/hello-algo.git
synced 2025-12-11 17:00:23 +08:00
add zig codes for Section 'Hash Map' and 'Linear Search'
This commit is contained in:
@@ -47,7 +47,8 @@ pub fn main() !void {
|
|||||||
const mem_allocator = mem_arena.allocator();
|
const mem_allocator = mem_arena.allocator();
|
||||||
var head = try inc.ListUtil.listToLinkedList(i32, mem_allocator, nums);
|
var head = try inc.ListUtil.listToLinkedList(i32, mem_allocator, nums);
|
||||||
var node = linearSearchLinkedList(i32, head, target);
|
var node = linearSearchLinkedList(i32, head, target);
|
||||||
std.debug.print("目标结点值 3 的对应结点对象为 {any}", .{node});
|
std.debug.print("目标结点值 3 的对应结点对象为 ", .{});
|
||||||
|
try inc.PrintUtil.printLinkedList(i32, node);
|
||||||
|
|
||||||
const getchar = try std.io.getStdIn().reader().readByte();
|
const getchar = try std.io.getStdIn().reader().readByte();
|
||||||
_ = getchar;
|
_ = getchar;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ pub fn ListNode(comptime T: type) type {
|
|||||||
// Initialize a list node with specific value
|
// Initialize a list node with specific value
|
||||||
pub fn init(self: *Self, x: i32) void {
|
pub fn init(self: *Self, x: i32) void {
|
||||||
self.val = x;
|
self.val = x;
|
||||||
|
self.next = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ pub fn TreeNode(comptime T: type) type {
|
|||||||
// Initialize a tree node with specific value
|
// Initialize a tree node with specific value
|
||||||
pub fn init(self: *Self, x: i32) void {
|
pub fn init(self: *Self, x: i32) void {
|
||||||
self.val = x;
|
self.val = x;
|
||||||
|
self.left = null;
|
||||||
|
self.right = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user