cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
searching value in binary_tree
searching value in binary_tree
Sep 24, 2013 at 4:06pm UTC
andrix
(15)
hello,
i have problem with these functions that return the id of a node of a binary tree.
int binary_tree::get_id_from_key(int key)
{
node *aux=search(root,key);
return aux->id_node;
}
node* binary_tree::search(node *&ptr,const int n)
{
if(ptr!=NULL)
{
if(ptr->key==n)
return ptr;
else if(n>ptr->key)
return search(ptr->right,n);
else return search(ptr->left,n);
}
else return 0;
}
the question is: is it right to return 0 if i don' t find the node containing value n?
in this case what should i return in the function get_id_from_key?
thanks in advance guys
Topic archived. No new replies allowed.