Hi:
I feel confused about the delete in binary search tree.
The following is the code:
Code:
void delete(struct bst_node** node) {
struct bst_node* old_node = *node;
if ((*node)->left == NULL) {
*node = (*node)->right;
free_node(old_node);
} else if ((*node)->right == NULL) {
*node = (*node)->left;
free_node(old_node);
} else {
delete node with two children
}
}
This problem is from the current node and its parents. In the above codes, obviously,
I cannot image how the parent node connect to the current node's right child, if (*node)->left == NULL; In theoretically, to find out the parent node, I should write following:
And then node p is the parent code of current. However, this algorithm not show in the function void delete(struct bst_node** node); why, and how to explain that.
Thanks a lot.
January 28th, 2013, 12:03 AM
BioPhysEngr
Re: about delete in BST
This question is better suited to the C++ subforum.
[ Thread moved, retaining a redirect in Algos & Data Structures ]