-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFLCardTree.java
More file actions
81 lines (56 loc) · 1.88 KB
/
FLCardTree.java
File metadata and controls
81 lines (56 loc) · 1.88 KB
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
public class FLCardTree {
private FLCardNode root;
public boolean ocg;
public FLCardTree(){};
public FLCardTree(FLCard initial) {
insert(initial);
}
public void insert(FLCard toAdd) {
if (ocg)
insertOcg(toAdd);
else if (root == null)
root = new FLCardNode(toAdd);
else
recursiveAdd(root, toAdd);
}
public void insertOcg(FLCard toAdd) {
if (root == null)
root = new FLCardNode(toAdd);
else
recursiveAddOcg(root, toAdd);
}
public void recursiveAdd(FLCardNode currentNode, FLCard insertedCard) {
if (insertedCard.compareTCG(currentNode.value) == -1) {
if (currentNode.left == null)
currentNode.left = new FLCardNode(insertedCard);
else
recursiveAdd(currentNode.left, insertedCard);
}
else if (currentNode.right == null)
currentNode.right = new FLCardNode(insertedCard);
else
recursiveAdd(currentNode.right, insertedCard);
}
public void recursiveAddOcg(FLCardNode currentNode, FLCard insertedCard) {
if (insertedCard.compareOCG(currentNode.value) == -1) {
if (currentNode.left == null)
currentNode.left = new FLCardNode(insertedCard);
else
recursiveAdd(currentNode.left, insertedCard);
}
else if (currentNode.right == null)
currentNode.right = new FLCardNode(insertedCard);
else
recursiveAdd(currentNode.right, insertedCard);
}
public void printTree() {
printInOrder(root);
}
public void printInOrder(FLCardNode current) {
if (current != null) {
printInOrder(current.right);
System.out.println(current);
printInOrder(current.left);
}
}
}