Finding the next larger element in BST.

Note that x is a node in the BST. Find the next larger element in BST . i.e next-larger(x).

Psedocode :

if (rightChild == NULL)     return minimum(right); else                                   y = parent(x);

while(y!= NULL && x=right(y) ) {   x = y;   y = parent(y); } return y;