This commit is contained in:
krahets
2023-10-15 21:18:21 +08:00
parent eda4539790
commit e181f9b491
10 changed files with 33 additions and 33 deletions
@@ -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;
}
}
+1 -1
View File
@@ -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);
}
+2 -2
View File
@@ -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;
}