add zig codes for Section 'Hash Map' and 'Linear Search'

This commit is contained in:
sjinzh 2023-01-13 23:40:37 +08:00
parent 722fb71bdd
commit 6f65c84e36
3 changed files with 5 additions and 1 deletions

View File

@ -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;

View File

@ -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;
} }
}; };
} }

View File

@ -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;
} }
}; };
} }