package test;
public class CheckBST {
static boolean isBST = false;
static boolean continueCheck = true;
private static void checkBST(Node root) {
if (continueCheck) {
Node left = root.getLeftNode();
Node right = root.getRightNode();
if (left.getValue() < root.getValue()
&& root.getValue() < right.getValue()) {
isBST = true;
if (null != left.getLeftNode() || null != left.getRightNode()) {
checkBST(left);
}
if (null != right.getLeftNode() || null != right.getRightNode()) {
checkBST(right);
}
} else {
isBST = false;
continueCheck = false;
}
}
}
public static void main(String[] args) {
Node left = new Node(2, new Node(1), new Node(3));
Node right = new Node(6, new Node(9), new Node(7));
Node root = new Node(4, left, right, true);
checkBST(root);
System.out.println("is BST ? ::" + isBST);
}
}