Skip to content

Commit 88e2162

Browse files
committed
update
1 parent c73e844 commit 88e2162

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+3788
-5791
lines changed

.editorconfig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# https://EditorConfig.org
2+
3+
# Top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file, utf-8 charset
7+
[*]
8+
end_of_line = lf
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
charset = utf-8
12+
indent_style = space
13+
indent_size = 4
14+
15+
[Makefile]
16+
indent_style = tab
17+
18+
[*.txt]
19+
insert_final_newline = unset
20+
21+
[*.md]
22+
insert_final_newline = unset

.gitignore

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
# MacOS Desktop Services Store
21
.DS_Store
3-
4-
# Editor
2+
.vs/
53
.vscode/
6-
.idea/
4+
.idea/
5+
*.o
6+
*.a
7+
*.exe
8+
9+
zig-out/
10+
zig-cache/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (C) 2023 hello-algo-zig
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
# Hello-Algo-Rust-Zig
2-
- [Rust](https://www.rust-lang.org/) and [Zig](https://ziglang.org/) programming language codes for the famous public project [krahets/hello-algo](https://github.com/krahets/hello-algo) <img src="https://img.shields.io/github/stars/krahets/hello-algo?style=social"/> about data structures and algorithms.
3-
- Go read this great open access e-book now -> [ hello-algo.com |《Hello, Algorithm》|《 Hello,算法 》](https://www.hello-algo.com/).
1+
# Hello-Algo-Zig
2+
- [**Zig**](https://ziglang.org/) programming language codes for the famous public project [krahets/hello-algo](https://github.com/krahets/hello-algo) <img src="https://img.shields.io/github/stars/krahets/hello-algo?style=social"/> about data structures and algorithms.
3+
- Go read this great open access e-book now -> [ hello-algo.com |《Hello, Algorithm》|《 Hello,算法 》](https://www.hello-algo.com/).
4+

build.zig

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
// File: build.zig
2+
// Created Time: 2023-01-07
3+
// Author: sjinzh (sjinzh@gmail.com)
4+
5+
const std = @import("std");
6+
7+
// Zig Version: 0.11.0-dev.3944+2e424e019
8+
// Zig Build Command: zig build -Doptimize=ReleaseFast
9+
// Zig Run Command: zig build run_* -Doptimize=ReleaseFast
10+
pub fn build(b: *std.Build) void {
11+
const target = b.standardTargetOptions(.{});
12+
const optimize = b.standardOptimizeOption(.{});
13+
14+
const group_name_path = .{
15+
// Source File: "chapter_computational_complexity/time_complexity.zig"
16+
// Run Command: zig build run_time_complexity -Doptimize=ReleaseFast
17+
.{ .name = "time_complexity", .path = "chapter_computational_complexity/time_complexity.zig" },
18+
19+
// Source File: "chapter_computational_complexity/worst_best_time_complexity.zig"
20+
// Run Command: zig build run_worst_best_time_complexity -Doptimize=ReleaseFast
21+
.{ .name = "worst_best_time_complexity", .path = "chapter_computational_complexity/worst_best_time_complexity.zig" },
22+
23+
// Source File: "chapter_computational_complexity/space_complexity.zig"
24+
// Run Command: zig build run_space_complexity -Doptimize=ReleaseFast
25+
.{ .name = "space_complexity", .path = "chapter_computational_complexity/space_complexity.zig" },
26+
27+
// Source File: "chapter_array_and_linkedlist/array.zig"
28+
// Run Command: zig build run_array -Doptimize=ReleaseFast
29+
.{ .name = "array", .path = "chapter_array_and_linkedlist/array.zig" },
30+
31+
// Source File: "chapter_array_and_linkedlist/linked_list.zig"
32+
// Run Command: zig build run_linked_list -Doptimize=ReleaseFast
33+
.{ .name = "linked_list", .path = "chapter_array_and_linkedlist/linked_list.zig" },
34+
35+
// Source File: "chapter_array_and_linkedlist/list.zig"
36+
// Run Command: zig build run_list -Doptimize=ReleaseFast
37+
.{ .name = "list", .path = "chapter_array_and_linkedlist/list.zig" },
38+
39+
// Source File: "chapter_array_and_linkedlist/my_list.zig"
40+
// Run Command: zig build run_my_list -Doptimize=ReleaseFast
41+
.{ .name = "my_list", .path = "chapter_array_and_linkedlist/my_list.zig" },
42+
43+
// Source File: "chapter_stack_and_queue/stack.zig"
44+
// Run Command: zig build run_stack -Doptimize=ReleaseFast
45+
.{ .name = "stack", .path = "chapter_stack_and_queue/stack.zig" },
46+
47+
// Source File: "chapter_stack_and_queue/linkedlist_stack.zig"
48+
// Run Command: zig build run_linkedlist_stack -Doptimize=ReleaseFast
49+
.{ .name = "linkedlist_stack", .path = "chapter_stack_and_queue/linkedlist_stack.zig" },
50+
51+
// Source File: "chapter_stack_and_queue/array_stack.zig"
52+
// Run Command: zig build run_array_stack -Doptimize=ReleaseFast
53+
.{ .name = "array_stack", .path = "chapter_stack_and_queue/array_stack.zig" },
54+
55+
// Source File: "chapter_stack_and_queue/queue.zig"
56+
// Run Command: zig build run_queue -Doptimize=ReleaseFast
57+
.{ .name = "queue", .path = "chapter_stack_and_queue/queue.zig" },
58+
59+
// Source File: "chapter_stack_and_queue/array_queue.zig"
60+
// Run Command: zig build run_array_queue -Doptimize=ReleaseFast
61+
.{ .name = "array_queue", .path = "chapter_stack_and_queue/array_queue.zig" },
62+
63+
// Source File: "chapter_stack_and_queue/linkedlist_queue.zig"
64+
// Run Command: zig build run_linkedlist_queue -Doptimize=ReleaseFast
65+
.{ .name = "linkedlist_queue", .path = "chapter_stack_and_queue/linkedlist_queue.zig" },
66+
67+
// Source File: "chapter_stack_and_queue/deque.zig"
68+
// Run Command: zig build run_deque -Doptimize=ReleaseFast
69+
.{ .name = "deque", .path = "chapter_stack_and_queue/deque.zig" },
70+
71+
// Source File: "chapter_stack_and_queue/linkedlist_deque.zig"
72+
// Run Command: zig build run_linkedlist_deque -Doptimize=ReleaseFast
73+
.{ .name = "linkedlist_deque", .path = "chapter_stack_and_queue/linkedlist_deque.zig" },
74+
75+
// Source File: "chapter_hashing/hash_map.zig"
76+
// Run Command: zig build run_hash_map -Doptimize=ReleaseFast
77+
.{ .name = "hash_map", .path = "chapter_hashing/hash_map.zig" },
78+
79+
// Source File: "chapter_hashing/array_hash_map.zig"
80+
// Run Command: zig build run_array_hash_map -Doptimize=ReleaseFast
81+
.{ .name = "array_hash_map", .path = "chapter_hashing/array_hash_map.zig" },
82+
83+
// Source File: "chapter_tree/binary_tree.zig"
84+
// Run Command: zig build run_binary_tree -Doptimize=ReleaseFast
85+
.{ .name = "binary_tree", .path = "chapter_tree/binary_tree.zig" },
86+
87+
// Source File: "chapter_tree/binary_tree_bfs.zig"
88+
// Run Command: zig build run_binary_tree_bfs -Doptimize=ReleaseFast
89+
.{ .name = "binary_tree_bfs", .path = "chapter_tree/binary_tree_bfs.zig" },
90+
91+
// Source File: "chapter_tree/binary_tree_dfs.zig"
92+
// Run Command: zig build run_binary_tree_dfs -Doptimize=ReleaseFast
93+
.{ .name = "binary_tree_dfs", .path = "chapter_tree/binary_tree_dfs.zig" },
94+
95+
// Source File: "chapter_tree/binary_search_tree.zig"
96+
// Run Command: zig build run_binary_search_tree -Doptimize=ReleaseFast
97+
.{ .name = "binary_search_tree", .path = "chapter_tree/binary_search_tree.zig" },
98+
99+
// Source File: "chapter_tree/avl_tree.zig"
100+
// Run Command: zig build run_avl_tree -Doptimize=ReleaseFast
101+
.{ .name = "avl_tree", .path = "chapter_tree/avl_tree.zig" },
102+
103+
// Source File: "chapter_heap/heap.zig"
104+
// Run Command: zig build run_heap -Doptimize=ReleaseFast
105+
.{ .name = "heap", .path = "chapter_heap/heap.zig" },
106+
107+
// Source File: "chapter_heap/my_heap.zig"
108+
// Run Command: zig build run_my_heap -Doptimize=ReleaseFast
109+
.{ .name = "my_heap", .path = "chapter_heap/my_heap.zig" },
110+
111+
// Source File: "chapter_searching/linear_search.zig"
112+
// Run Command: zig build run_linear_search -Doptimize=ReleaseFast
113+
.{ .name = "linear_search", .path = "chapter_searching/linear_search.zig" },
114+
115+
// Source File: "chapter_searching/binary_search.zig"
116+
// Run Command: zig build run_binary_search -Doptimize=ReleaseFast
117+
.{ .name = "binary_search", .path = "chapter_searching/binary_search.zig" },
118+
119+
// Source File: "chapter_searching/hashing_search.zig"
120+
// Run Command: zig build run_hashing_search -Doptimize=ReleaseFast
121+
.{ .name = "hashing_search", .path = "chapter_searching/hashing_search.zig" },
122+
123+
// Source File: "chapter_searching/two_sum.zig"
124+
// Run Command: zig build run_two_sum -Doptimize=ReleaseFast
125+
.{ .name = "two_sum", .path = "chapter_searching/two_sum.zig" },
126+
127+
// Source File: "chapter_sorting/bubble_sort.zig"
128+
// Run Command: zig build run_bubble_sort -Doptimize=ReleaseFast
129+
.{ .name = "bubble_sort", .path = "chapter_sorting/bubble_sort.zig" },
130+
131+
// Source File: "chapter_sorting/insertion_sort.zig"
132+
// Run Command: zig build run_insertion_sort -Doptimize=ReleaseFast
133+
.{ .name = "insertion_sort", .path = "chapter_sorting/insertion_sort.zig" },
134+
135+
// Source File: "chapter_sorting/quick_sort.zig"
136+
// Run Command: zig build run_quick_sort -Doptimize=ReleaseFast
137+
.{ .name = "quick_sort", .path = "chapter_sorting/quick_sort.zig" },
138+
139+
// Source File: "chapter_sorting/merge_sort.zig"
140+
// Run Command: zig build run_merge_sort -Doptimize=ReleaseFast
141+
.{ .name = "merge_sort", .path = "chapter_sorting/merge_sort.zig" },
142+
143+
// Source File: "chapter_sorting/radix_sort.zig"
144+
// Run Command: zig build run_radix_sort -Doptimize=ReleaseFast
145+
.{ .name = "radix_sort", .path = "chapter_sorting/radix_sort.zig" },
146+
};
147+
148+
inline for (group_name_path) |name_path| {
149+
const exe = b.addExecutable(.{
150+
.name = name_path.name,
151+
.root_source_file = .{ .path = name_path.path },
152+
.target = target,
153+
.optimize = optimize,
154+
});
155+
exe.addModule("include", b.addModule("", .{
156+
.source_file = .{ .path = "include/include.zig" },
157+
}));
158+
b.installArtifact(exe);
159+
const run_cmd = b.addRunArtifact(exe);
160+
run_cmd.step.dependOn(b.getInstallStep());
161+
if (b.args) |args| run_cmd.addArgs(args);
162+
const run_step = b.step("run_" ++ name_path.name, "Run the app");
163+
run_step.dependOn(&run_cmd.step);
164+
}
165+
}

0 commit comments

Comments
 (0)