Binary Search Tree : Lowest Common Ancestor

  • + 0 comments

    Had a similar thing with C but I'm getting seg faults. Any ideas? It works for half the test cases;

    struct node *lca(struct node *root, int v1, int v2) {
        if(root != NULL && root->data < v1 && root->data < v2){
            return lca(root->left, v1, v2);
        }
        if(root != NULL && root->data > v1 && root->data > v2){
            return lca(root->right, v1, v2);
        }
        else return root;
    }