I am confused by the following algorithm:
public static boolean checkBST(TreeNode n) {
if (n == null) {
return true;
}
// Check / recurse left
if (!checkBST(n.left)) {
return false;
}
// Check current
if (last_printed != null && n.data <= last_printed) {
return false;
}
last_printed = n.data;
// Check / recurse right
if (!checkBST(n.right)) {
return false;
}
return true;
}
I understand the in-order traversal, and understand comparing the left child of the current node to make sure it's <= to the parent in the line with n.data <= last_printed, but where in this recursion do we check whether the right child is greater than the parent?