You are viewing a single comment's thread. Return to all comments →
Node *add1 [25]; Node *add2[25]; int i=0,j=0; Node *lca(Node *root, int v1,int v2) { // Write your code here.
if(v1>root->data) { root=lca(root->right,v1,v2); add1[i++]=root; } else if(v2>root->data) { root=lca(root->right,v1,v2); add2[j++]=root; } else if(v1<root->data) { root=lca(root->left,v1,v2); add1[i++]=root; } else if(v2<root->data) { root=lca(root->left,v1,v2); add2[j++]=root; } Node *a; for(int i=0;i<25;i++){ for(int j=0;j<25;j++){ if(add1[i]==add2[2]) {a= add1[i]; return a;} } } }
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 →
Node *add1 [25]; Node *add2[25]; int i=0,j=0; Node *lca(Node *root, int v1,int v2) { // Write your code here.