Why this is wrong?
you are building tree in wrong way
it is not mention to build balanced BST
so make bst in simple fashion take a node and insert it
like
node* insertnode(int d, node*startnode) {
if (startnode == NULL) {
node*nn = new node(d);
return nn;
}
if (startnode->data > d) {
startnode->left = insertnode(d, startnode->left);
}
else {
startnode->right = insertnode(d, startnode->right);
}
return startnode;
}
after using this function your code is passing all testcase
i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course
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.