My code is running on online compiler but its showing segmentation fault here.
Please check my code https://ide.codingblocks.com/s/311951
Hey @kodivine0, the build function seems to be fine, but the segmentation fault is coming because of the print tree function.
I just simply used preorder traversal for print function, and it’s working fine. You can check it here.
but sir, the question demands some other o/p. I designed my program according to it.
Okay @kodivine0, not an issue. The main problem with the code is in print function you’re assigning left and right nodes before checking if the node is NULL or not. So, just put a base case on top on print function:
if(root==NULL ) return ;
and it’ll work, you can check it out here.
Hope this helps.
thank you sir ! 