In the binary tree tutorial, i am having a little trouble understanding one part of the code.
Code:
node *btree::search(int key, node *leaf)
{
if(leaf!=NULL)
{
if(key==leaf->key_value)
return leaf;
if(key<leaf->key_value)
return search(key, leaf->left);
else
return search(key, leaf->right);
}
else return NULL;
}
why is it neccessary to use node(a struct) as the return type? (rest of the code is in tutorial, too long to post )
instead of using something like this, and changing the rest of the code to match it.
Code:
int *btree::search(int key, node *leaf)
{
if(leaf!=NULL)
{
if(key==leaf->key_value)
return leaf;
if(key<leaf->key_value)
return search(key, leaf->left);
else
return search(key, leaf->right);
}
else return NULL;
}
just curious, all i need is to be pointed in the right direction, thanks in advance