These are my functions:
struct node
{
int key_value;
struct node *left;
struct node *right;
};
struct node *root = 0;
void destroy_tree(struct node *leaf)
{
if( leaf != 0 )
{
destroy_tree(leaf->left);
destroy_tree(leaf->right);
free( leaf );
}
}
insert(int key, struct node **leaf)
{
if( *leaf == 0 )
{
*leaf = (struct node*) malloc( sizeof( struct node ) );
(*leaf)->key_value = key;
/* initialize the children to null */
(*leaf)->left = 0;
(*leaf)->right = 0;
}
else if(key < (*leaf)->key_value)
{
insert( key, &(*leaf)->left );
}
else if(key > (*leaf)->key_value)
{
insert( key, &(*leaf)->right );
}
}
struct node *search(int key, struct node *leaf)
{
if( leaf != 0 )
{
if(key==leaf->key_value)
{
return leaf;
}
else if(key<leaf->key_value)
{
return search(key, leaf->left);
}
else
{
return search(key, leaf->right);
}
}
else return 0;
}
Should I call the insert function from the AddCustomer() method and then call the search function from the SearchCustomer() method ?
Please I really need help, I am only a beginner with C.
This post has been edited by baavgai: 09 January 2013 - 05:47 AM
Reason for edit:: tagged

New Topic/Question
Reply



MultiQuote





|