Lowest common ancester in binary search tree



static node *lca(struct node *root,int n1,int n2)
    {
    if (root == NULL) return NULL;

 
    if (root->data > n1 && root->data > n2)
        return lca(root->left, n1, n2);

    if (root->data < n1 && root->data < n2)
        return lca(root->right, n1, n2);

    return root;

      
    }

Comments

Popular posts from this blog

How whatsapp works

Android N Developer Preview? It's exciting for most of you