-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckBST.java
More file actions
36 lines (30 loc) · 720 Bytes
/
Copy pathCheckBST.java
File metadata and controls
36 lines (30 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package rank;
/**
* created by @author suraj on 27/10/19
*/
public class CheckBST {
static boolean checkBST(BTreeHeight.Node root) {
BTreeHeight.Node left = root.left;
if (left != null) {
if (left.data > root.data) {
return false;
} else {
checkBST(left);
}
}
BTreeHeight.Node right = root.right;
if (right != null) {
if (right.data < root.data) {
return false;
} else {
checkBST(root);
}
}
return true;
}
class Node {
int data;
BTreeHeight.Node left;
BTreeHeight.Node right;
}
}