>I need some hints on how to do the insert and find.
The big trick to just about anything in a bst is getting the search down pat. To search you check the current node, if the thing you're looking for is less than the current node, you move left. Otherwise you move right. When you get the a match, you found what you're looking for. If it's not found, you'll get to a null pointer:
Code:
int search ( struct node *t, int x )
{
if ( t == NULL ) /* Not found */
return 0;
else if ( t->thing == x ) /* Found */
return 1;
else if ( x < t->thing ) /* Go left */
return search ( t->left, x );
else /* Go right */
return search ( t->right, x );
}
Insertion is just a planned unsuccessful search, where you insert a new node when you get to the bottom. The big trick is that you need to update the tree, so going back up you need to make sure that the higher parts of the tree know about the changes to the lower parts:
Code:
struct node *insert ( struct node *t, int x )
{
if ( t == NULL ) { /* Not found, insert */
t = malloc ( sizeof *t );
t->thing = x;
t->left = t->right = NULL;
return t;
}
else if ( t->thing == x ) /* Found, ignore */
return t;
else if ( x < t->thing ) /* Go left */
return search ( t->left, x );
else /* Go right */
return search ( t->right, x );
}
The biggest part to most bst routines is the search, so if you understand that you'll be well on your way.
Cheers!