class BSB { private BSB left; private BSB right; private int value; public BSB(int v) { value = v; } public int min() { if (left == null) return value; return left.min(); } public int max() { if (right == null) return value; return right.max(); } public BSB removeMax() { if (right == null) return left; right = right.removeMax(); return this; } public boolean isSearchTree() { boolean leftIsSearchTree, rightIsSearchTree; int leftMax, rightMin; if (left == null) { leftIsSearchTree = true; leftMax = Integer.MIN_VALUE; } else { leftIsSearchTree = left.isSearchTree(); leftMax = left.max(); } if (right == null) { rightIsSearchTree = true; rightMin = Integer.MAX_VALUE; } else { rightIsSearchTree = right.isSearchTree(); rightMin = right.min(); } return leftIsSearchTree && rightIsSearchTree && value > leftMax && value < rightMin; } }