Print BST keys in the given range wrong answer

Print BST keys in the given range wrong answer.plz highlight the mistake and make changes in the code.
and also i want to know when we print nodes in the range we follow the in order traversal as output is sorted?

problem : https://online.codingblocks.com/app/player/39658/content/55448/5300/code-challenge?code=dMMTqPOJGRFN6VrgOy5r0J8Pg5cU2M1N

code : https://ide.codingblocks.com/s/194037

plz reply asap.


hey here i have applied the recursive approach for the problem
your logic to print the sorted array is also correct however the problem with your code is the building of the bst, u have the build the bst in the order provided in the question and not by sorting the array
that is also provided in the following code:
bstnode *insertinbst(bstnode *root, int data)
{
if(root==NULL)
{
return new bstnode(data);
}
if(data<=root->data)
{
root->left = insertinbst(root->left, data);
}
else
root->right = insertinbst(root->right, data);
return root;
}
bstnode *build()
{
int d;
cin>>d;
bstnode *root = NULL;
while(d!=-1)
{
root = insertinbst(root,d);
cin>>d;
}
return root;
}
in main()
{…
bstnode *root = build();
}

use this to build your bst
if your doubt is solved, kindly mark it as resolved

hey @sengarankit98 if your doubt is solved, please mark it as resolved

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.