Print BST keys in the given range it is giving error in output


this is the ide

Anoushka, you are using a wrong approach in building the tree, Use the following approach in your code :

void buildtree(node *&root)
{
while(N>0)
{
cin>>data;
root=insertInBST(root,data);
}
}
Then use the simple way to insert node in BST , i.e if root==NULL , return data,

if(data<=root->data)
insert in left,
else
insertin Right.

Try following this approach