Click here to Skip to main content
15,799,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
.[^] // full code

else if(root->left == NULL) {         //confusing part in deleting node with one child    
struct Node *temp = root;
root = root->right;
delete temp;

After deleting the temp, what about the link between temp's parent and current root ? I am little confused here. pls explain .

What I have tried:

I have tried linking the root with the last leaf , but somehow I am losing the link of the root to connect it with the leaf node.
Updated 7-Dec-16 10:55am

1 solution

before deletion
root = node1
      /    \
    NULL  node2
          /   \

after deletion
root = node2
       /   \
Share this answer
Member 12719168 7-Dec-16 20:39pm    
if I want to delete node 2 ,the format is connect node1 with the child of node2 (in case of only one child ) After recursion node2 becomes my root .. so root =root->right ......will connection b/w the parent will not be cutoff ... ? can you clarify that part alone. Thanks!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900