Learning Algorithms and Data Structures (35) - (deleted node binary) tree structure

Binary Tree - Delete Node

In claim
1. If the removed node is a leaf node, deleting the node
2. If the removed node is non-leaf node, which subtree is deleted.
3. Test, No. 5 deleted leaf node subtree and 3.

Complete binary tree delete operation node:

It provides that:
1. If the deleted node is a leaf node, then remove the node
2. If nodes are non-leaf node delete, delete the sub-tree.

Ideas:
First, to deal with:
consider if the tree is empty tree root, if there is only one root node, then the binary tree blank

// then the following operation is
1. Because our binary tree is unidirectional, so we determined whether the child nodes of the current node is the node to be deleted, but can not determine the current node is not the node to be deleted
2. If the current node's child nodes do not empty, and left child node is to be removed, it will this.left = null; and return (recursive delete end)
3. If the right child of the current node node is not empty, and the right child node is to be removed, it is love that this.right = null; and returns (end recursive delete)
4. If step 2 and step 3 is not deleted node, then we requires subtrees left recursive delete
5. If the fourth node does not delete, you should remove recursively right subtree.
Here Insert Picture Description

Published 92 original articles · won praise 51 · views 20000 +

Guess you like

Origin blog.csdn.net/mzc_love/article/details/104750332