i am getting correct elements but their order is different pls help
π‘ Delete nodes from BST
@Pritika hey pritika replace left child instead right child.
node* replace=root->right;
node*replace =root->left;
now rebuild your logic for this suggested case
sir i tried that also and in that case the output on ide comes correct but when i submit the code it shows wrong ans
@Pritika hey pritika there is basically three mistake in your code
donβt take array as input
make a insert function and pass a root and values a parameters and this function will be a recursive function like if value is small as compare to current root data will send to the left otherwise send it the right.
and return type is node* this function return a root
and in the main function {
int t;int n,m;
cin>>t;
int data1,data2;
while(tβ)
{
cin>>n;
node* root=NULL;
while(n--)
{
cin>>data1;
root=insertbst(root,data1);
}
cin>>m;
while(m--){
cin>>data2;
root=deleteInBST(root,data2);
}
print(root);
cout<<endl;
}
return 0;
}
and in the delete function
while(replace->left!=NULL){
replace=replace->left;
}
there is no need of this function
node* deletebst(node* root,int b[],int m ){
for(int i=0;i<m;i++){
root= deletef(root,b[i]);
}
return root;
}
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.