- public boolean checkBST(Node root) {
- return isBST(root,Integer.MIN_VALUE,Integer.MAX_VALUE);
- }
- public boolean isBST(Node root,int a,int b) {
- if(root == null) return true;
- if( ((root.data > a) && (root.data<b)) && (isBST(root.left,a,root.data)) && (isBST(root.right,root.data,b)) ) {
- return true;
- }
- return false;
- }
Raw Paste