From 97733f1a7d0d2a3523c7cec49d0233e2fd3067f7 Mon Sep 17 00:00:00 2001 From: krahets Date: Mon, 25 Nov 2024 19:12:22 +0800 Subject: [PATCH] build --- docs/chapter_heap/heap.md | 4 +- .../replace_linear_by_hashing.md | 8 +- docs/chapter_sorting/counting_sort.md | 1 + docs/chapter_sorting/radix_sort.md | 6 +- .../array_representation_of_tree.md | 11 +- docs/chapter_tree/avl_tree.md | 2 +- docs/chapter_tree/binary_search_tree.md | 8 +- docs/chapter_tree/binary_tree_traversal.md | 46 +++++--- docs/index.html | 75 ++++-------- en/docs/chapter_tree/index.md | 5 +- en/docs/index.html | 107 ++++++------------ zh-Hant/docs/chapter_graph/graph.md | 2 +- zh-Hant/docs/index.html | 81 +++++-------- 13 files changed, 141 insertions(+), 215 deletions(-) diff --git a/docs/chapter_heap/heap.md b/docs/chapter_heap/heap.md index c9ffeaa1c..31748fbba 100644 --- a/docs/chapter_heap/heap.md +++ b/docs/chapter_heap/heap.md @@ -167,8 +167,8 @@ comments: true /* 初始化堆 */ // 初始化小顶堆 PriorityQueue minHeap = new(); - // 初始化大顶堆(使用 lambda 表达式修改 Comparator 即可) - PriorityQueue maxHeap = new(Comparer.Create((x, y) => y - x)); + // 初始化大顶堆(使用 lambda 表达式修改 Comparer 即可) + PriorityQueue maxHeap = new(Comparer.Create((x, y) => y.CompareTo(x))); /* 元素入堆 */ maxHeap.Enqueue(1, 1); diff --git a/docs/chapter_searching/replace_linear_by_hashing.md b/docs/chapter_searching/replace_linear_by_hashing.md index 0626c6b63..2d80fc7c1 100755 --- a/docs/chapter_searching/replace_linear_by_hashing.md +++ b/docs/chapter_searching/replace_linear_by_hashing.md @@ -490,12 +490,12 @@ comments: true } /* 哈希表元素插入 */ - void insert(HashTable *h, int key, int val) { - HashTable *t = find(h, key); + void insert(HashTable **h, int key, int val) { + HashTable *t = find(*h, key); if (t == NULL) { HashTable *tmp = malloc(sizeof(HashTable)); tmp->key = key, tmp->val = val; - HASH_ADD_INT(h, key, tmp); + HASH_ADD_INT(*h, key, tmp); } else { t->val = val; } @@ -512,7 +512,7 @@ comments: true *returnSize = 2; return res; } - insert(hashtable, nums[i], i); + insert(&hashtable, nums[i], i); } *returnSize = 0; return NULL; diff --git a/docs/chapter_sorting/counting_sort.md b/docs/chapter_sorting/counting_sort.md index e0eefcd6b..0272d3223 100644 --- a/docs/chapter_sorting/counting_sort.md +++ b/docs/chapter_sorting/counting_sort.md @@ -825,6 +825,7 @@ $$ // 使用结果数组 res 覆盖原数组 nums memcpy(nums, res, size * sizeof(int)); // 5. 释放内存 + free(res); free(counter); } ``` diff --git a/docs/chapter_sorting/radix_sort.md b/docs/chapter_sorting/radix_sort.md index 7380d86e5..8f7098d81 100644 --- a/docs/chapter_sorting/radix_sort.md +++ b/docs/chapter_sorting/radix_sort.md @@ -574,6 +574,7 @@ $$ void countingSortDigit(int nums[], int size, int exp) { // 十进制的位范围为 0~9 ,因此需要长度为 10 的桶数组 int *counter = (int *)malloc((sizeof(int) * 10)); + memset(counter, 0, sizeof(int) * 10); // 初始化为 0 以支持后续内存释放 // 统计 0~9 各数字的出现次数 for (int i = 0; i < size; i++) { // 获取 nums[i] 第 k 位,记为 d @@ -597,13 +598,16 @@ $$ for (int i = 0; i < size; i++) { nums[i] = res[i]; } + // 释放内存 + free(res); + free(counter); } /* 基数排序 */ void radixSort(int nums[], int size) { // 获取数组的最大元素,用于判断最大位数 int max = INT32_MIN; - for (size_t i = 0; i < size - 1; i++) { + for (int i = 0; i < size; i++) { if (nums[i] > max) { max = nums[i]; } diff --git a/docs/chapter_tree/array_representation_of_tree.md b/docs/chapter_tree/array_representation_of_tree.md index 7c953a9cf..47ff9a23c 100644 --- a/docs/chapter_tree/array_representation_of_tree.md +++ b/docs/chapter_tree/array_representation_of_tree.md @@ -1020,18 +1020,11 @@ comments: true /* 层序遍历 */ fn level_order(&self) -> Vec { - let mut res = vec![]; - // 直接遍历数组 - for i in 0..self.size() { - if let Some(val) = self.val(i) { - res.push(val) - } - } - res + self.tree.iter().filter_map(|&x| x).collect() } /* 深度优先遍历 */ - fn dfs(&self, i: i32, order: &str, res: &mut Vec) { + fn dfs(&self, i: i32, order: &'static str, res: &mut Vec) { if self.val(i).is_none() { return; } diff --git a/docs/chapter_tree/avl_tree.md b/docs/chapter_tree/avl_tree.md index 5c85e6302..3648fe73f 100644 --- a/docs/chapter_tree/avl_tree.md +++ b/docs/chapter_tree/avl_tree.md @@ -188,7 +188,7 @@ AVL 树既是二叉搜索树,也是平衡二叉树,同时满足这两类二 ```c title="" /* AVL 树节点结构体 */ - TreeNode struct TreeNode { + typedef struct TreeNode { int val; int height; struct TreeNode *left; diff --git a/docs/chapter_tree/binary_search_tree.md b/docs/chapter_tree/binary_search_tree.md index 237c70b54..0602ab231 100755 --- a/docs/chapter_tree/binary_search_tree.md +++ b/docs/chapter_tree/binary_search_tree.md @@ -1447,7 +1447,7 @@ comments: true // 删除节点 cur if !Rc::ptr_eq(&cur, self.root.as_ref().unwrap()) { let left = pre.borrow().left.clone(); - if left.is_some() && Rc::ptr_eq(&left.as_ref().unwrap(), &cur) { + if left.is_some() && Rc::ptr_eq(left.as_ref().unwrap(), &cur) { pre.borrow_mut().left = child; } else { pre.borrow_mut().right = child; @@ -1468,11 +1468,11 @@ comments: true break; } } - let tmpval = tmp.unwrap().borrow().val; + let tmp_val = tmp.unwrap().borrow().val; // 递归删除节点 tmp - self.remove(tmpval); + self.remove(tmp_val); // 用 tmp 覆盖 cur - cur.borrow_mut().val = tmpval; + cur.borrow_mut().val = tmp_val; } } } diff --git a/docs/chapter_tree/binary_tree_traversal.md b/docs/chapter_tree/binary_tree_traversal.md index f6fa62878..d0a90e11c 100755 --- a/docs/chapter_tree/binary_tree_traversal.md +++ b/docs/chapter_tree/binary_tree_traversal.md @@ -700,12 +700,17 @@ comments: true fn pre_order(root: Option<&Rc>>) -> Vec { let mut result = vec![]; - if let Some(node) = root { - // 访问优先级:根节点 -> 左子树 -> 右子树 - result.push(node.borrow().val); - result.extend(pre_order(node.borrow().left.as_ref())); - result.extend(pre_order(node.borrow().right.as_ref())); + fn dfs(root: Option<&Rc>>, res: &mut Vec) { + if let Some(node) = root { + // 访问优先级:根节点 -> 左子树 -> 右子树 + let node = node.borrow(); + res.push(node.val); + dfs(node.left.as_ref(), res); + dfs(node.right.as_ref(), res); + } } + dfs(root, &mut result); + result } @@ -713,12 +718,17 @@ comments: true fn in_order(root: Option<&Rc>>) -> Vec { let mut result = vec![]; - if let Some(node) = root { - // 访问优先级:左子树 -> 根节点 -> 右子树 - result.extend(in_order(node.borrow().left.as_ref())); - result.push(node.borrow().val); - result.extend(in_order(node.borrow().right.as_ref())); + fn dfs(root: Option<&Rc>>, res: &mut Vec) { + if let Some(node) = root { + // 访问优先级:左子树 -> 根节点 -> 右子树 + let node = node.borrow(); + dfs(node.left.as_ref(), res); + res.push(node.val); + dfs(node.right.as_ref(), res); + } } + dfs(root, &mut result); + result } @@ -726,12 +736,18 @@ comments: true fn post_order(root: Option<&Rc>>) -> Vec { let mut result = vec![]; - if let Some(node) = root { - // 访问优先级:左子树 -> 右子树 -> 根节点 - result.extend(post_order(node.borrow().left.as_ref())); - result.extend(post_order(node.borrow().right.as_ref())); - result.push(node.borrow().val); + fn dfs(root: Option<&Rc>>, res: &mut Vec) { + if let Some(node) = root { + // 访问优先级:左子树 -> 右子树 -> 根节点 + let node = node.borrow(); + dfs(node.left.as_ref(), res); + dfs(node.right.as_ref(), res); + res.push(node.val); + } } + + dfs(root, &mut result); + result } ``` diff --git a/docs/index.html b/docs/index.html index 146e0aefb..bfb257f9b 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,30 +1,24 @@ - -
+ +
- - + + 初识算法 - + 复杂度 - + 数组与链表 - + 栈与队列 @@ -52,8 +46,7 @@ 排序 - + 分治 @@ -61,8 +54,7 @@ 回溯 - + 动态规划 @@ -73,25 +65,20 @@ @@ -148,8 +133,7 @@
获取纸质书 - +
@@ -162,8 +146,7 @@
在线阅读 - +
@@ -174,8 +157,7 @@
下载 PDF - +
@@ -209,8 +191,7 @@
- +

动画图解

@@ -227,8 +208,7 @@
- +

一键运行

@@ -243,8 +223,7 @@
- +

互助学习

@@ -280,16 +259,14 @@
- Reviewer: curtishd + Reviewer: curtishd
curtishd
Kotlin
@@ -338,8 +315,7 @@
- Reviewer: night-cruise + Reviewer: night-cruise
night-cruise
Rust
@@ -373,8 +349,7 @@

贡献者

本书在开源社区一百多位贡献者的共同努力下不断完善,感谢他们付出的时间与精力!

- Contributors + Contributors
diff --git a/en/docs/chapter_tree/index.md b/en/docs/chapter_tree/index.md index 97926620f..4e22d1d78 100644 --- a/en/docs/chapter_tree/index.md +++ b/en/docs/chapter_tree/index.md @@ -9,10 +9,9 @@ icon: material/graph-outline !!! abstract - The towering tree, vibrant with it's deep roots and lush leaves, branches spreading wide. + The towering tree exudes a vibrant essence, boasting profound roots and abundant foliage, yet its branches are sparsely scattered, creating an ethereal aura. - It vividly illustrates the concept of divide-and-conquer in data. - + It shows us the vivid form of divide-and-conquer in data. ## Chapter contents - [7.1   Binary tree](binary_tree.md) diff --git a/en/docs/index.html b/en/docs/index.html index 07a650021..01a95b5a5 100644 --- a/en/docs/index.html +++ b/en/docs/index.html @@ -1,30 +1,24 @@ - -
+ +
- - + + Encounter with Algorithms - + Complexity analysis - + Array and linked list - + Stack and queue @@ -52,8 +46,7 @@ Sorting - + Divide and conquer @@ -61,8 +54,7 @@ Backtracking - + Dynamic programming @@ -73,25 +65,20 @@ @@ -148,8 +133,7 @@
Paperbook - +
@@ -162,8 +146,7 @@
Read online - +
@@ -174,8 +157,7 @@
Download PDF - +
@@ -209,8 +191,7 @@
- +

Animated illustrations

@@ -227,8 +208,7 @@
- +

Off-the-shelf code

@@ -243,8 +223,7 @@
- +

Learning together

@@ -280,16 +259,14 @@
- Reviewer: curtishd + Reviewer: curtishd
curtishd
Kotlin
@@ -338,8 +315,7 @@
- Reviewer: night-cruise + Reviewer: night-cruise
night-cruise
Rust
@@ -374,71 +350,61 @@
@@ -448,10 +414,9 @@

Contributors

-

This book has been enhanced through the collaborative efforts of more than 100 contributors. Thanks for their invaluable time and input!

+

This book has been optimized by the efforts of over 180 contributors. We sincerely thank them for their invaluable time and contributions!

- Contributors + Contributors
diff --git a/zh-Hant/docs/chapter_graph/graph.md b/zh-Hant/docs/chapter_graph/graph.md index 886c3b591..b42548965 100644 --- a/zh-Hant/docs/chapter_graph/graph.md +++ b/zh-Hant/docs/chapter_graph/graph.md @@ -68,7 +68,7 @@ $$ 鄰接矩陣具有以下特性。 -- 頂點不能與自身相連,因此鄰接矩陣主對角線元素沒有意義。 +- 在簡單圖中,頂點不能與自身相連,此時鄰接矩陣主對角線元素沒有意義。 - 對於無向圖,兩個方向的邊等價,此時鄰接矩陣關於主對角線對稱。 - 將鄰接矩陣的元素從 $1$ 和 $0$ 替換為權重,則可表示有權圖。 diff --git a/zh-Hant/docs/index.html b/zh-Hant/docs/index.html index 72dce4b1c..10919b59f 100644 --- a/zh-Hant/docs/index.html +++ b/zh-Hant/docs/index.html @@ -1,30 +1,24 @@ - -
+ +
- - + + 初識演算法 - + 複雜度 - + 陣列與鏈結串列 - + 堆疊與佇列 @@ -52,8 +46,7 @@ 排序 - + 分治 @@ -61,8 +54,7 @@ 回溯 - + 動態規劃 @@ -73,25 +65,20 @@ @@ -148,8 +133,7 @@
紙質書(簡中) - +
@@ -162,8 +146,7 @@
線上閱讀 - +
@@ -174,8 +157,7 @@
PDF(簡中) - +
@@ -209,8 +191,7 @@
- +

動畫圖解

@@ -227,8 +208,7 @@
- +

一鍵執行

@@ -243,8 +223,7 @@
- +

互助學習

@@ -280,16 +259,14 @@
- Reviewer: curtishd + Reviewer: curtishd
curtishd
Kotlin
@@ -338,8 +315,7 @@
- Reviewer: night-cruise + Reviewer: night-cruise
night-cruise
Rust
@@ -374,15 +350,13 @@
@@ -394,8 +368,7 @@

貢獻者

本書在開源社群一百多位貢獻者的共同努力下不斷完善,感謝他們付出的時間與精力!

- Contributors + Contributors