This commit is contained in:
krahets
2023-08-28 23:52:41 +08:00
parent 2f0f154b3c
commit 88a746f493
7 changed files with 21 additions and 21 deletions

View File

@@ -18,7 +18,7 @@ AVL 树既是二叉搜索树也是平衡二叉树,同时满足这两类二叉
### 节点高度
在操作 AVL 树时,我们需要获取节点高度,因此需要为 AVL 树的节点类添加 `height` 变量。
由于 AVL 树的相关操作需要获取节点高度,因此我们需要为节点类添加 `height` 变量。
=== "Java"

View File

@@ -202,11 +202,11 @@
如下图所示,当待删除节点的度为 $0$ 时,表示该节点是叶节点,可以直接删除。
![在二叉搜索树中删除节点(度为 0](binary_search_tree.assets/bst_remove_case1.png)
![在二叉搜索树中删除节点(度为 0 ](binary_search_tree.assets/bst_remove_case1.png)
如下图所示,当待删除节点的度为 $1$ 时,将待删除节点替换为其子节点即可。
![在二叉搜索树中删除节点(度为 1](binary_search_tree.assets/bst_remove_case2.png)
![在二叉搜索树中删除节点(度为 1 ](binary_search_tree.assets/bst_remove_case2.png)
当待删除节点的度为 $2$ 时,我们无法直接删除它,而需要使用一个节点替换该节点。由于要保持二叉搜索树“左 $<$ 根 $<$ 右”的性质,**因此这个节点可以是右子树的最小节点或左子树的最大节点**。
@@ -216,7 +216,7 @@
2. 将 `tmp` 的值覆盖待删除节点的值,并在树中递归删除节点 `tmp` 。
=== "<1>"
![二叉搜索树删除节点示例](binary_search_tree.assets/bst_remove_case3_step1.png)
![二叉搜索树删除节点(度为 2 ](binary_search_tree.assets/bst_remove_case3_step1.png)
=== "<2>"
![bst_remove_case3_step2](binary_search_tree.assets/bst_remove_case3_step2.png)