Skip to content

Commit

Permalink
remove node from binary tree
Browse files Browse the repository at this point in the history
  • Loading branch information
jainkhere committed May 5, 2022
1 parent 8e66683 commit 7a63aac
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions binary_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ NODE * merge_two_trees (NODE * r1, NODE * r2) {
// Check if any one of both the trees is null
// if any one is null, then return
if (r1 == NULL)
return r1;
return r2;
if (r2 == NULL)
return r1;

Expand Down Expand Up @@ -239,7 +239,6 @@ void remove_node (NODE ** addr_of_root, int value_to_remove) {
// otherwise set right child as right child of parent
// 3. Remove node_to_remove using free.
if (right_child != NULL) {
// printf("Value of right of NTR -> \n", (*right_child).value);
(*right_child).parent = parent;

if (node_to_remove == (*parent).left) {
Expand All @@ -249,7 +248,7 @@ void remove_node (NODE ** addr_of_root, int value_to_remove) {
(*parent).right = right_child;
}

free(right_child);
free(node_to_remove);
}

// If no above condition is met then that means we have to remove leaf node
Expand Down Expand Up @@ -304,9 +303,6 @@ int main(void) {

remove_node(&root, 15);

// node = find_node(root, 10);
// printf("Value of found node -> %d\n", (*node).value);

// Print tree using in order traversal
printf("Inorder traversal -> ");
print_in_order(root);
Expand Down

0 comments on commit 7a63aac

Please sign in to comment.