getting 4 testcases as wrong answer.pls tell the correct code
Delete nodes from bst
Hello @yutikakhanna,
-
Your code is even failing for the sample test case.
1
7
5 3 2 4 7 6 8
3
2 3 5
Your Output:
4 7 6 8
Expected Output:
6 4 7 8
Reason:
You have missed an important part of the question:
Note : In case of node with 2 children, consider its inorder successor as its replacement
which means you have to replace the node with the node having value just greater than the current node.
In simple words, the left most element of the right subtree of the current node.
You have rather replaced it with the rightmost element of the left subtree.(which is not asked by the question) -
The output of each test case should be in a separate line.
Hope, this would help.
Give a like if you are satisfied.
pls tell in the form of a code
Hello @yutikakhanna,
Solution:
-
node *t=root->right; while(t->left!=NULL) t=t->left; swap(root->data,t->data); root->right=del(root->right,t->data); -
Add the following statement as the last statement inside while condition:
cout<<endl;
https://ide.codingblocks.com/s/199935
Hope, this would help.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.