You are viewing a single comment's thread. Return to all comments →
It is better to first check if you have already found the lce and then decide which path to go.
To, the same idea without brackets would be like this:
node * lca(node * root, int v1,int v2) { int diff1 = root->data - v1, diff2 = root->data - v2; if (diff1 * diff2 <= 0) return root; if (diff1 < 0) return lca(root->right, v1, v2); return lca(root->left, v1, v2); }
Seems like cookies are disabled on this browser, please enable them to open this website
Binary Search Tree : Lowest Common Ancestor
You are viewing a single comment's thread. Return to all comments →
It is better to first check if you have already found the lce and then decide which path to go.
To, the same idea without brackets would be like this: