// Similar to other suggestions, but without tail recursion.
ptr search(ptr root, int value)
{
ptr result = 0;
while(root && !result)
{
result = (root->tag == value) ? root : search(root->left,
value);
root = root->right;
}
return result;
}
On Jul 12, 8:28 am, anonymous procrastination <[email protected]>
wrote:
> Hello,
>
> Suppose you have to search a particular node in a binary tree.
> The code is quite simple. Pick up any traversal and see if any node
> matches the value.
> Doubt I have is that how to pull out of the recursive function at the
> instant node is found.
> In iterative algos we use a break.
> Here I can use a global flag variable. But any other bettr way of
> doing this?
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.