Created
July 15, 2014 22:41
-
-
Save jyhjuzi/77590c414117f9e4d76d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Q4_5{ | |
public static void main(String[] args){ | |
TreeNode root1 = new TreeNode(7,new TreeNode(2,new TreeNode(1),new TreeNode(3,null,new TreeNode(8))),new TreeNode(11)); | |
System.out.println(isBST(root1,Integer.MAX_VALUE,Integer.MIN_VALUE)); | |
} | |
static boolean isBST(TreeNode root, int max, int min){ | |
if(root == null) | |
return true; | |
int value = (Integer) root.value; | |
if(value>max || value<min) | |
return false; | |
if(!isBST(root.left,value,min)) | |
return false; | |
if(!isBST(root.right,max,value)) | |
return false; | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment