-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathh7.txt
84 lines (67 loc) · 1.32 KB
/
h7.txt
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
Homework 7
1. (a) All of the above are trees except ii.
(b) i, iii, iv
(c) i, iv
(d) 4 3 2 6 5
(e) 7 20 30 23 38 23 11
2. (a)
30
/ \
11 36
/ \ / \
9 12 33 45
/ \ \ / \
6 10 22 39 47
(b)
30
/ \
11 36
/ \ / \
9 12 33 45
\ \ / \
10 22 39 47
/
37
(c)
30
/ \
11 36
/ \ / \
9 22 33 45
\ / \
10 39 47
(d)
22
/ \
11 36
/ \ / \
9 12 33 45
\ / \
10 39 47
(e)
33
/ \
11 36
/ \ \
9 12 45
\ \ / \
10 22 39 47
3. public static boolean isBST(BSTnode<K> root){
boolean x = true;
if(root = null) return true;
if(root.getLeft().compareTo(root.getKey()) > 0) {
return false;
}
if(root.getRight().compareTo(root.getKey()) < 0) {
return false;
}
if(root.getLeft().compareTo(root.getKey()) < 0) {
x = isBST(root.getLeft());
}
if(x == false) return false;
if(root.getRight().compareTo(root.getKey()) > 0) {
x = isBST(root.getRight());
}
if(x == false) return false;
return true;
}