You are viewing a single comment's thread. Return to all comments →
Queue ino=new LinkedList(); boolean checkBST(Node root) { inorder(root); int[] arr = ino.stream().mapToInt(i->i).toArray();//convert ArrayList to primitive int array int[] brr = ino.stream().mapToInt(i->i).toArray(); //ArrayList brr=new ArrayList(arr); Arrays.sort(arr); /* for(int i:arr) System.out.print(i+","); System.out.println(""); for(int i:brr) System.out.print(i+",");*/ if(Arrays.equals(arr,brr)) return true; else return false; } void inorder(Node root) { if(root==null) return; inorder(root.left); ino.add(root.data); inorder(root.right); }
Is This a Binary Search Tree?
You are viewing a single comment's thread. Return to all comments →
Queue ino=new LinkedList(); boolean checkBST(Node root) { inorder(root); int[] arr = ino.stream().mapToInt(i->i).toArray();//convert ArrayList to primitive int array int[] brr = ino.stream().mapToInt(i->i).toArray(); //ArrayList brr=new ArrayList(arr); Arrays.sort(arr); /* for(int i:arr) System.out.print(i+","); System.out.println(""); for(int i:brr) System.out.print(i+",");*/ if(Arrays.equals(arr,brr)) return true; else return false; } void inorder(Node root) { if(root==null) return; inorder(root.left); ino.add(root.data); inorder(root.right); }