tree closestSharedAncestor(tree root, tree node1, tree node2, int
&result)
{
tree returnValue = 0;
if (root)
{
if (root == node1) result += 1;
if (root == node2) result += 2;
int sum = 0;
tree returnLeft = closestSharedAncestor(root->left, node1, node2,
sum);
if (returnLeft) returnValuet = returnLeft;
else
{
tree returnRight = closestSharedAncestor(root->right, node1,
node2, sum);
if (returnRight) returnValue = returnRight;
else if (sum == 3) returnValue = root;
}
result += sum;
}
return returnValue;
}
On Aug 9, 9:56 am, Raman <[email protected]> wrote:
> Can anyone give me the recursive algo to find closest ancestor of two nodes
> in a tree(not a BST).
--
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.