Is Binary Search Tree - Java
public class IsBST { public static boolean isBST(Tree treeNode) { return isBST(treeNode,Integer.MIN_VALUE,Integer.MAX_VALUE); } private static boolean isBST(Tree treeNode, int minValue, int maxValue) { if(treeNode == null) return true; if(treeNode.data < minValue || treeNode.data > maxValue) return false; if(!isBST(treeNode.left,minValue,treeNode.data) && !isBST(treeNode.right,treeNode.data,maxValue)) return false; return true; } public static void main(String[] args) { Tree myTree = new Tree(4); myTree.left = new Tree(2); myTree.right = new Tree(6); myTree.left.left = new Tree(1); myTree.left.right = new Tree(3); myTree.right.left = new Tree(7); System.out.println(Boolean.toString(isBST(myTree))); } } class Tree{ int data; Tree left; Tree right; public Tree(int data) { this.data = data; this.left = this.right = null; } }