Getting segmentation fault in the buildtree function im trying to create

i followed the whole video for binary tree creating a tree and i still keep getting segmentation fault.
here’s my code:


please help!

you are getting segmentation fault
because you have provided wrong input
correct input is
3 5 -1 6 -1 -1 5 -1 -1
last one should be -1 not 1

but i want to add 1 as the right child of 5 in the tree, what to do in that case?

this is should be the correct output for that
3 5 -1 6 -1 -1 5 -1 1 -1 -1

oh okay, that makes sense. Thank you!

okay then plz mark the doubt as resolved from your side

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.