Create tree using preorder and inorder

i wrote the main function of creating a tree and I am printing in Inorder just to check if tree is right or wrong. but its showing segmentation fault. please check the code.

Hi… there are many errors in ur code… go through this https://ide.codingblocks.com/s/604242

I know I have error in printing order. I am talking about that but what is the error in my createtree function?

basically u would have to use static variable…i suggest u to watch the video lecture again… Prateek bhaiya has explained it very well over there…

i got your point. I have watched again. but why do we need to use static variable only?

hi… so static variable is used so that same variable is used in the whole program(like for lifetime of program) and its value changes accordingly…

then here its just that i am not taking static variable but I am writing the right logic of this code?

ya more or less logic seems correct only… for any issues u can refer my code also

please check this code. it is working 20%

ok… let me check…

have you checked the question?

ur logic was correct… error was due to just printing format…
image
just do this ur code will pass all test cases…

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.