My code is showing wrong output.Could you please tell me where i am going wrong?
https://ide.codingblocks.com/s/207886
Build BST. Code showing wrong input
You are using wrong approach to build your tree… You need to convert the array to BST… since you are given sorted array…
Follow the approach as , :
node *arrtoBST(int ar[1001],int start,int end)
{
if(start>end)
{
return NULL;
}
int mid=(start+end)/2;
node *root=new node(ar[mid]);
root->left=arrtoBST(ar,start,mid-1);
root->right=arrtoBST(ar,mid+1,end);
return root;
}