https://ide.codingblocks.com/s/105830 I have printed the preorder traversal still the order is not correct. Please check
Output Sequence problem
@samriddhi.srivastava2017
In this problem , in the particular case when the node to be deleted has two children , you are picking the inorder successor ( min value from right subtree ) as its replacement. However the online judge in this problem expects you to choose inorder predecessor ( max value from left subtree ) as its replacement. While both are suitable candidates for being the replacements , it depends from problem to problem which they ask. Make the according changes and let me know if you need any help with it.
Thanks Sir. Corrected that but the hidden test case failed.
@samriddhi.srivastava2017
You were not deleting any nodes when the node had 1 child. You were simply passing on the child back without actually deleting the node. This created a problem. Also in Line No. 68 , you were passing on right child when it should be the left child.
Change your code to this
else if(root->left==NULL){
node* temp = root->right;
delete root;
return temp;
}
else if(root->right==NULL){
node* temp = root->left;
delete root;
return temp;
}
This code snippet starts at Line No. 63
Thank you sir. Its working now 