-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTreeExpandSE.java
44 lines (38 loc) · 912 Bytes
/
TreeExpandSE.java
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
public class TreeExpandSE {
public TreeExpandSE left;
public TreeExpandSE right;
/**
* Build a list of length n - 3
* At the end build a tree of height 3
*
* @author Joel Beckmann
*/
public static void main(String[] args) {
int n = args.length;
TreeExpandSE tree = new TreeExpandSE();
build(tree, n);
}
public TreeExpandSE() {
this.left = null;
this.right = null;
}
public static void build(TreeExpandSE t, int length) {
TreeExpandSE l = new TreeExpandSE();
t.left = l;
if (length > 3) {
build(l, length - 1);
} else {
expand(l, length);
}
}
public static void expand(TreeExpandSE t, int length) {
if (length > 0) {
TreeExpandSE l = new TreeExpandSE();
TreeExpandSE r = new TreeExpandSE();
t.left = l;
t.right = r;
expand(l, length - 1);
expand(r, length - 1);
}
}
}