Please check code for Construct BST from preorder problem


getting segm dault.

hello @sahilkhan2312000131

check now->

Not giving correct output, Can u please check.

check now->

just added one extra check i==n the return NULL

The output is not BST

is ur preorder input is correct?

i have given input that is present online and it is working fine->

to check bst tree , best idea is to check its inorder traversal ,it will always be in increasing order

Input is:
6
5 3 7 1 6 8
Output should be:
5,
3,7,
1,6,8
But code is giving:
5,
3,6,
7,8,
1,

whats the exact problem name (the problem title)…

if u have link then pls share it with me

there is no link, sir has told in a video to construct a bst using preorder and trick is to use create inorder fom preorder then make bst.

u were giving wrong preorder in input.
just now i checked the video.
this is the order that he is giving.
6
5 3 1 7 6 8
try now.

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.