Can you see why I am getting the wrong answer
you have to simply build bst
you are trying to make balanced bst by calculating mid and so on
you can do this simply like this
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;
}
void BuildTree(int *arr, int n) {
for (int i = 0; i < n; i++) {
rootnode = insertnode(arr[i], rootnode);
}
}
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.