The code compiles but gives the wrong answer.I think there is a problem with the way input is being taken.Please help.
Bst keys in a range
You’re not making the tree properly, make a BST, not a normal tree. (for a BST you must compare the value of node with the root node and accordingly place it)
Thankyou I shall try.
I tried using the sort function in main function.So in this case I am getting the preorder printed but the output format is not correct,Also the printbstkeys function is not working.Would you please help?
@srshubhi398 don’t sort the array,
See in the base case, if root is NULL you can make root with value arr[i]
But if root is not null, then compare the value of root with arr[i] and accordingly see if you should insert it in left subtrees or right subtree
I tried this.But the printbstkeys function is not printing anything and the preorder function gives the right answer but the format is wrong,preorder gets printed before every integer.Please look into this.I am highly confused.

@srshubhi398 you havent made any of the changes that i suggested… please refer to this for clarity
I did not make the change in the case when root was null,I guess.Thanks a lot,for the help. 
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.