-
Notifications
You must be signed in to change notification settings - Fork 0
/
BTreeGeneration.java
65 lines (41 loc) · 1.37 KB
/
BTreeGeneration.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
public class BTreeGeneration {
/**
*
*
* Maria Sigal, Marina Khitynova
*
*
*
*/
public static void main(String[] args) {
//8(5(9, 3), 3(6, 2(5, 1)))
BTNode<Integer> rn = new BTNode<Integer>(1, null, null, null);
BTNode<Integer> ln = new BTNode<Integer>(5, null, null, null);
BTNode<Integer> pn = new BTNode<Integer>(2, null, ln, rn);
rn.setParent(pn);
ln.setParent(pn);
ln = new BTNode<Integer>(6, null, null, null);
BTNode<Integer> lr = new BTNode<Integer>(3,null,ln,pn);
ln.setParent(lr);
pn.setParent(lr);
ln = new BTNode<Integer>(9,null,null,null );
rn = new BTNode<Integer>(3, null, null,null);
pn =new BTNode<Integer>(5,null,ln,rn);
ln.setParent(pn);
rn.setParent(pn);
BinTree<Integer> bTree =new BinTree<Integer>();
bTree.root().setElement(8);
bTree.root().setLeft(pn);
bTree.root().setRight(lr);
pn.setParent(bTree.root());
lr.setParent(bTree.root());
System.out.println("our tree notation: " + BinTree.outputBT(bTree));
/*BinTree.depth(bTree);
System.out.println("our tree after depth method : " + BinTree.outputBT(bTree));
BinTree.height(bTree);
System.out.println("our tree after height method : " + BinTree.outputBT(bTree));
*/
System.out.println("preorder: " +bTree.preOrder(bTree));
System.out.println("postorder: " +bTree.postOrder(bTree));
}
}