its customary to name the top of the tree (node 1) "head"
struct tree* head = NULL;
After allocating a new tree node check of head == NULL, if it does then just set head = newnode.
Ancient Dragon
Achieved Level 70
32,275 posts since Aug 2005
Reputation Points: 5,852
Solved Threads: 2,590
Skill Endorsements: 70
I thought I could say node1->left = &node2; // left = the address of node 2.
Is that right?
What happened when you tried it? Didn't it work?
And what The Dragon said is true. Make a pointer named head that will point to the first node. That way if the first node has to change it's easy to add a node and relink to the new first node
WaltP
Posting Sage w/ dash of thyme
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 37