Why is preorder printed wrong
Refer this code.
Hope it clears all ur doubts.
understood your code, but what was error in mine
In this question, you have been given a sequence of numbers and you have to build a BST from it. Then you have to print the preorder traversal of the BST you have created.
But what u are doing is sorting the elements before building the tree. So that’s not correct.
and if u just delete the sort statement then the tree being build is a normal tree and not a BST. So u have to build the BST like this.

Hope it clears all ur doubts.
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.