You are viewing a single comment's thread. Return to all comments →
just modified a little thanx it saved my time
boolean checkBST(Node root) { return checkBST1(root,Integer.MIN_VALUE,Integer.MAX_VALUE); } boolean checkBST1(Node root, int min,int max) { if(root==null) return true; if(root.data <=min || root.data >=max) return false; return(checkBST1(root.left,min,root.data) && checkBST1(root.right,root.data,max)); }
Is This a Binary Search Tree?
You are viewing a single comment's thread. Return to all comments →
just modified a little thanx it saved my time
boolean checkBST(Node root) { return checkBST1(root,Integer.MIN_VALUE,Integer.MAX_VALUE); } boolean checkBST1(Node root, int min,int max) { if(root==null) return true; if(root.data <=min || root.data >=max) return false; return(checkBST1(root.left,min,root.data) && checkBST1(root.right,root.data,max)); }