It is the solution for inorder successor without having parent pointer..

node *inorder_succ(node *root, int x)
    {
        node *prev=NULL;
        node *p=findspcl(root,&prev, x);

        if(p->r)
        {
            p=p->r;
            while(p->l)
                p=p->l;
            return p;
        }
        else
        {
            return prev;
        }
    }

node *findspcl(node *root,node **prev, int x)
    {

        if(x == root->a)
        {
            return root;
        }
        else if( root->l!=NULL && x < root->a)
        {
            *prev=root;
            return findspcl(root->l,prev,x);
        }
        else if(root->r!=NULL && root->a < x)
        {
            return findspcl(root->r,prev,x);
        }
        else
            return NULL;
    }

-- 
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.

Reply via email to