Problem Statement
Pattern:
Solution
Node inorderPredecessor(Node node, int key) {
Node pre = null;
while(node != null) {
if(key <= node.data) node = node.left;
else {
pre = node;
node = node.right;
} }
return pre;
}
Node inorderSuccessor(Node node, int key) {
Node succ = null;
while(node != null) {
if(key >= node.data) node = node.right;
else {
succ = node;
node = node.left;
} }
return succ;
}