Find a String: X, which may or may not exist in the AVL tree. Can i have the pseudo code to get X if it exists OR find the next biggest string after X?
I have done the code for successor. Successor finds the next biggest node.
protected BSTVertex successor(BSTVertex T)
{
if (T.right != null) // this subtree has right subtree
return findMin2(T.right); // the successor is the minimum of right subtree
else {
BSTVertex par = T.parent;
BSTVertex cur = T;
// if par(ent) is not root and cur(rent) is its right children
while ((par != null) && (cur == par.right)) {
cur = par; // continue moving up
par = cur.parent;
}
return par == null ? null : par; // this is the successor of T
}
}
Example if the tree consist of numbers 1,2,3,4,7,9. If i want to find 6, it should return me 7 as 6 does not exists and the next biggest value is 7