diff --git a/codes/c/chapter_computational_complexity/recursion.c b/codes/c/chapter_computational_complexity/recursion.c index 8241e3bf..14692700 100644 --- a/codes/c/chapter_computational_complexity/recursion.c +++ b/codes/c/chapter_computational_complexity/recursion.c @@ -20,12 +20,12 @@ int recur(int n) { /* 使用迭代模拟递归 */ int forLoopRecur(int n) { int stack[1000]; // 借助一个大数组来模拟栈 - int top = 0; + int top = -1; // 栈顶索引 int res = 0; // 递:递归调用 for (int i = n; i > 0; i--) { // 通过“入栈操作”模拟“递” - stack[top++] = i; + stack[1 + top++] = i; } // 归:返回结果 while (top >= 0) { @@ -64,6 +64,9 @@ int main() { res = recur(n); printf("\n递归函数的求和结果 res = %d\n", res); + res = forLoopRecur(n); + printf("\n使用迭代模拟递归求和结果 res = %d\n", res); + res = tailRecur(n, 0); printf("\n尾递归函数的求和结果 res = %d\n", res); diff --git a/codes/c/chapter_graph/graph_adjacency_list.c b/codes/c/chapter_graph/graph_adjacency_list.c index dd8260ba..4510d002 100644 --- a/codes/c/chapter_graph/graph_adjacency_list.c +++ b/codes/c/chapter_graph/graph_adjacency_list.c @@ -224,9 +224,9 @@ void removeVertex(GraphAdjList *graph, unsigned int index) { // 将顶点前移 for (int i = index; i < graph->size - 1; i++) { graph->vertices[i] = graph->vertices[i + 1]; // 顶点前移 - graph->vertices[i]->pos--; // 所有前移的顶点索引值减1 + graph->vertices[i]->pos--; // 所有前移的顶点索引值减 1 } - graph->vertices[graph->size - 1] = 0; // 将被删除顶点的位置置 0 + graph->vertices[graph->size - 1] = 0; graph->size--; // 释放内存 freeVertex(vet); diff --git a/docs/chapter_tree/avl_tree.md b/docs/chapter_tree/avl_tree.md index 602f7d9a..d397a175 100644 --- a/docs/chapter_tree/avl_tree.md +++ b/docs/chapter_tree/avl_tree.md @@ -207,7 +207,7 @@ AVL 树既是二叉搜索树也是平衡二叉树,同时满足这两类二叉 ``` -“节点高度”是指从该节点到最远叶节点的距离,即所经过的“边”的数量。需要特别注意的是,叶节点的高度为 0 ,而空节点的高度为 -1 。我们将创建两个工具函数,分别用于获取和更新节点的高度。 +“节点高度”是指从该节点到其最远叶节点的距离,即所经过的“边”的数量。需要特别注意的是,叶节点的高度为 0 ,而空节点的高度为 -1 。我们将创建两个工具函数,分别用于获取和更新节点的高度。 ```src [file]{avl_tree}-[class]{a_v_l_tree}-[func]{update_height} diff --git a/docs/chapter_tree/binary_tree.md b/docs/chapter_tree/binary_tree.md index 1b4d6b67..d01e82c3 100644 --- a/docs/chapter_tree/binary_tree.md +++ b/docs/chapter_tree/binary_tree.md @@ -200,7 +200,7 @@ - 节点的「度 degree」:节点的子节点的数量。在二叉树中,度的取值范围是 0、1、2 。 - 二叉树的「高度 height」:从根节点到最远叶节点所经过的边的数量。 - 节点的「深度 depth」:从根节点到该节点所经过的边的数量。 -- 节点的「高度 height」:从最远叶节点到该节点所经过的边的数量。 +- 节点的「高度 height」:从距离该节点最远的叶节点到该节点所经过的边的数量。 ![二叉树的常用术语](binary_tree.assets/binary_tree_terminology.png) diff --git a/docs/index.assets/hello_algo_header.png b/docs/index.assets/hello_algo_header.png new file mode 100644 index 00000000..aff19ebe Binary files /dev/null and b/docs/index.assets/hello_algo_header.png differ