Update .gitignore

Add build script for Zig.
This commit is contained in:
krahets
2023-02-09 22:57:25 +08:00
parent 3465b300e9
commit ec25970e8e
30 changed files with 226 additions and 532 deletions
@@ -13,7 +13,7 @@ fn hashingSearchArray(comptime T: type, map: std.AutoHashMap(T, T), target: T) T
return map.get(target).?;
}
// 哈希查找(数组
// 哈希查找(链表
fn hashingSearchLinkedList(comptime T: type, map: std.AutoHashMap(T, *inc.ListNode(T)), target: T) ?*inc.ListNode(T) {
// 哈希表的 key: 目标结点值,value: 结点对象
// 若哈希表中无此 key ,返回 null
@@ -6,7 +6,7 @@ const std = @import("std");
const inc = @import("include");
// 线性查找(数组)
fn linearSearchList(comptime T: type, nums: std.ArrayList(T), target: T) T {
fn linearSearchArray(comptime T: type, nums: std.ArrayList(T), target: T) T {
// 遍历数组
for (nums.items) |num, i| {
// 找到目标元素, 返回其索引
@@ -38,7 +38,7 @@ pub fn main() !void {
var nums = std.ArrayList(i32).init(std.heap.page_allocator);
defer nums.deinit();
try nums.appendSlice(&[_]i32{ 1, 5, 3, 2, 4, 7, 5, 9, 10, 8 });
var index = linearSearchList(i32, nums, target);
var index = linearSearchArray(i32, nums, target);
std.debug.print("目标元素 3 的索引 = {}\n", .{index});
// 在链表中执行线性查找