upgrade zig codes to 0.11.0-dev.3379+629f0d23b (#563)

* upgrade zig codes to 0.11.0-dev.3379+629f0d23b

* upgrade zig codes to 0.11.0-dev.3379+629f0d23b
This commit is contained in:
sjinzh
2023-06-25 20:59:00 +08:00
committed by GitHub
parent 62e8f0df50
commit 41b7b229a3
22 changed files with 264 additions and 460 deletions
@@ -61,4 +61,4 @@ pub fn main() !void {
std.debug.print("目标元素 6 的索引 = {}\n", .{index});
_ = try std.io.getStdIn().reader().readByte();
}
}
@@ -30,7 +30,7 @@ pub fn main() !void {
// 初始化哈希表
var map = std.AutoHashMap(i32, i32).init(std.heap.page_allocator);
defer map.deinit();
for (nums) |num, i| {
for (nums, 0..) |num, i| {
try map.put(num, @intCast(i32, i)); // key: 元素,value: 索引
}
var index = hashingSearchArray(i32, map, target);
@@ -8,7 +8,7 @@ const inc = @import("include");
// 线性查找(数组)
fn linearSearchArray(comptime T: type, nums: std.ArrayList(T), target: T) T {
// 遍历数组
for (nums.items) |num, i| {
for (nums.items, 0..) |num, i| {
// 找到目标元素, 返回其索引
if (num == target) {
return @intCast(T, i);
@@ -51,5 +51,4 @@ pub fn main() !void {
try inc.PrintUtil.printLinkedList(i32, node);
_ = try std.io.getStdIn().reader().readByte();
}
}
+2
View File
@@ -53,4 +53,6 @@ pub fn main() !void {
res = (try twoSumHashTable(&nums, target)).?;
std.debug.print("\n方法二 res = ", .{});
inc.PrintUtil.printArray(i32, &res);
_ = try std.io.getStdIn().reader().readByte();
}