mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-24 18:55:36 +08:00
build
This commit is contained in:
@ -186,7 +186,18 @@ comments: true
|
|||||||
=== "C"
|
=== "C"
|
||||||
|
|
||||||
```c title="preorder_traversal_i_compact.c"
|
```c title="preorder_traversal_i_compact.c"
|
||||||
[class]{}-[func]{preOrder}
|
/* 前序遍历:例题一 */
|
||||||
|
void preOrder(TreeNode *root) {
|
||||||
|
if (root == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (root->val == 7) {
|
||||||
|
// 记录解
|
||||||
|
vectorPushback(res, root, sizeof(int));
|
||||||
|
}
|
||||||
|
preOrder(root->left);
|
||||||
|
preOrder(root->right);
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "Zig"
|
=== "Zig"
|
||||||
|
@ -1632,7 +1632,24 @@ status: new
|
|||||||
=== "C"
|
=== "C"
|
||||||
|
|
||||||
```c title="recursion.c"
|
```c title="recursion.c"
|
||||||
[class]{}-[func]{forLoopRecur}
|
/* 使用迭代模拟递归 */
|
||||||
|
int forLoopRecur(int n) {
|
||||||
|
int stack[1000]; // 借助一个大数组来模拟栈
|
||||||
|
int top = 0;
|
||||||
|
int res = 0;
|
||||||
|
// 递:递归调用
|
||||||
|
for (int i = n; i > 0; i--) {
|
||||||
|
// 通过“入栈操作”模拟“递”
|
||||||
|
stack[top++] = i;
|
||||||
|
}
|
||||||
|
// 归:返回结果
|
||||||
|
while (top >= 0) {
|
||||||
|
// 通过“出栈操作”模拟“归”
|
||||||
|
res += stack[top--];
|
||||||
|
}
|
||||||
|
// res = 1+2+3+...+n
|
||||||
|
return res;
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "Zig"
|
=== "Zig"
|
||||||
|
@ -1027,7 +1027,11 @@ $$
|
|||||||
=== "Zig"
|
=== "Zig"
|
||||||
|
|
||||||
```zig title="space_complexity.zig"
|
```zig title="space_complexity.zig"
|
||||||
[class]{}-[func]{function}
|
// 函数
|
||||||
|
fn function() i32 {
|
||||||
|
// 执行某些操作
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// 常数阶
|
// 常数阶
|
||||||
fn constant(n: i32) void {
|
fn constant(n: i32) void {
|
||||||
|
@ -1152,7 +1152,7 @@ comments: true
|
|||||||
/* 链表节点 */
|
/* 链表节点 */
|
||||||
struct node {
|
struct node {
|
||||||
Pair *pair;
|
Pair *pair;
|
||||||
struct Node *next;
|
struct node *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct node Node;
|
typedef struct node Node;
|
||||||
|
@ -965,14 +965,18 @@ index = hash(key) % capacity
|
|||||||
|
|
||||||
```swift title="array_hash_map.swift"
|
```swift title="array_hash_map.swift"
|
||||||
/* 键值对 */
|
/* 键值对 */
|
||||||
class Pair {
|
class Pair: Equatable {
|
||||||
var key: Int
|
public var key: Int
|
||||||
var val: String
|
public var val: String
|
||||||
|
|
||||||
init(key: Int, val: String) {
|
public init(key: Int, val: String) {
|
||||||
self.key = key
|
self.key = key
|
||||||
self.val = val
|
self.val = val
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static func == (lhs: Pair, rhs: Pair) -> Bool {
|
||||||
|
lhs.key == rhs.key && lhs.val == rhs.val
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 基于数组简易实现的哈希表 */
|
/* 基于数组简易实现的哈希表 */
|
||||||
|
Reference in New Issue
Block a user