0450_delete-node-in-a-bst

command
v0.0.0-...-60194e6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2020 License: Unlicense Imports: 0 Imported by: 0

README

0450_delete-node-in-a-bst

分支都在代码里写明了, 删除节点时, 最麻烦的情况是被删节点同时有左右节点. 此时我们的目的, 是要找到被删除节点所在子树的predecessor(或者successor).

一个节点的predecessor(就是大小顺序紧挨着的小一点的数), 就是它的往左走一步后一直往右直到不能走下去为止的节点.

predecessor节点:

  • 是叶子节点的话: 直接提上来.
  • 不是叶子节点的话: 用predecessor的值覆盖被删节点, 然后在predecessor为根的子树里递归做删除操作.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL