mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-11 23:16:07 +00:00
build
This commit is contained in:
@@ -458,18 +458,18 @@ comments: true
|
||||
}
|
||||
|
||||
/* 深度优先遍历 */
|
||||
private void Dfs(int i, string order, List<int> res) {
|
||||
private void DFS(int i, string order, List<int> res) {
|
||||
// 若为空位,则返回
|
||||
if (!Val(i).HasValue)
|
||||
return;
|
||||
// 前序遍历
|
||||
if (order == "pre")
|
||||
res.Add(Val(i).Value);
|
||||
Dfs(Left(i), order, res);
|
||||
DFS(Left(i), order, res);
|
||||
// 中序遍历
|
||||
if (order == "in")
|
||||
res.Add(Val(i).Value);
|
||||
Dfs(Right(i), order, res);
|
||||
DFS(Right(i), order, res);
|
||||
// 后序遍历
|
||||
if (order == "post")
|
||||
res.Add(Val(i).Value);
|
||||
@@ -478,21 +478,21 @@ comments: true
|
||||
/* 前序遍历 */
|
||||
public List<int> PreOrder() {
|
||||
List<int> res = new();
|
||||
Dfs(0, "pre", res);
|
||||
DFS(0, "pre", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
/* 中序遍历 */
|
||||
public List<int> InOrder() {
|
||||
List<int> res = new();
|
||||
Dfs(0, "in", res);
|
||||
DFS(0, "in", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
/* 后序遍历 */
|
||||
public List<int> PostOrder() {
|
||||
List<int> res = new();
|
||||
Dfs(0, "post", res);
|
||||
DFS(0, "post", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2361,7 +2361,7 @@ AVL 树的节点插入操作与二叉搜索树在主体上类似。唯一的区
|
||||
```c title="avl_tree.c"
|
||||
/* 删除节点 */
|
||||
// 由于引入了 stdio.h ,此处无法使用 remove 关键词
|
||||
void removeNode(aVLTree *tree, int val) {
|
||||
void removeItem(aVLTree *tree, int val) {
|
||||
TreeNode *root = removeHelper(tree->root, val);
|
||||
}
|
||||
|
||||
|
||||
@@ -1357,7 +1357,7 @@ comments: true
|
||||
```c title="binary_search_tree.c"
|
||||
/* 删除节点 */
|
||||
// 由于引入了 stdio.h ,此处无法使用 remove 关键词
|
||||
void removeNode(binarySearchTree *bst, int num) {
|
||||
void removeItem(binarySearchTree *bst, int num) {
|
||||
// 若树为空,直接提前返回
|
||||
if (bst->root == NULL)
|
||||
return;
|
||||
@@ -1399,7 +1399,7 @@ comments: true
|
||||
}
|
||||
int tmpVal = tmp->val;
|
||||
// 递归删除节点 tmp
|
||||
removeNode(bst, tmp->val);
|
||||
removeItem(bst, tmp->val);
|
||||
// 用 tmp 覆盖 cur
|
||||
cur->val = tmpVal;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user