I'm trying to write a code for a binary search tree and I currently have it written to traverse when I give it a pointer to the root to start the function on, however I need it to be able to start from the root without being passed a pointer as well as being able to pass it a pointer to any node and start a traversal from that point down throughout its leaves. Any help much appreciated, thanks!
EDIT: I have figured out how to do what I want it to, but now I am getting a segmentation fault before even reaching my first test case. Code has been edited to new version.
line 45 - I think you want to update the Root pointer that's defined on line 28 Root = NULL; instead of creating a local pointer in the function node * Root = NULL;.
Insert function - if you're not initializing the root, you're recursively calling the insert function. I think this is where your segmentation fault is coming from because the recursion is infinite.
If you're insert a node that's not the root, instead of calling insert again, you need to be creating that node and updating the appropriate left and right pointers. I tweaked the code to create a node instead of calling insert again, and added some output. That got rid of the seg fault (at least for the creation of the BST).
1 2 3 4 5 6 7 8
root is now 10
5 is < than 10
15 is >= than 10
5 is < than 10
6 is < than 10
7 is < than 10
8 is < than 10
89 is >= than 10