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

@@ -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)