Hi:(adsbygoogle = window.adsbygoogle || []).push({});

I was in a maze about delete in binary search tree. The followings

is its codes:

This problem is from the current node and its parents. In the above codes, obviously,Code (Text):

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

}

}

I cannot image how the parent node connect to the current node's right child when if (*node)->left == NULL; In theoretically, to find out the parent node, I should write codes like following:

and then when delete the current, the function will connect the parent node's right child toCode (Text):

struct bst_node* p;

if(current_node!=null)

{

p=current_node; current_node=current->right;

}

current node's right child. However, the codes in top section not including this part, I didn't

know why and how it work. Any instruction is appreciated, thanks.

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# [C] about delete in BST

**Physics Forums | Science Articles, Homework Help, Discussion**