-
Notifications
You must be signed in to change notification settings - Fork 0
/
h8.txt
55 lines (37 loc) · 1.06 KB
/
h8.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
HW 8
1.
public static BinaryTreenode<K> convert2LCRS(TrinaryTreenode<K> triTreeRoot) {
if(triTreeRoot.getLeft() == null) {
BinaryTreenode<k> leaf =
new BinaryTreenode<K>(triTreeRoot.getKey());
return leaf;
}
BinaryTreenode<K> left = convert2LCRS(triTreeRoot.getLeft());
BinaryTreenode<K> right = convert2LCRS(triTreeRoot.getRight());
BinaryTreenode<K> mid = convert2LCRS(triTreeRoot.getMid());
left.setRight(mid );
mid.setRight(right);
BinaryTreenode<K> root = new BinaryTreenode<K>(triTreeRoot.getKey());
root.setRight(left);
return(root);
}
2. (a)
(44)
/ \
[22] [88]
/ \ / \
(11)(33) (66) (99)
/ \
[55] [77]
(b)
(55)
/ \
[22] [77]
/ \ / \
(11) (33) (66) (88)
/ \
[44] [99]
3. (a)
[88, 72, 33, 43, 26, 19, 21, 5, 9]
(b)
[x, 17, 22, 24, 47, 32, 32, 26]