-
Notifications
You must be signed in to change notification settings - Fork 2
/
Node.java
97 lines (91 loc) · 1.69 KB
/
Node.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import java.util.*;
public class Node
{
Node leftChild;
Node rightChild;
int value;
Node root;
int leftCount;
int rightCount;
ColorMatrix C; //reference to the colorMatrix that this Node is in
public Node(int value, ColorMatrix C)
{
this.leftChild = null;
this.rightChild = null;
this.value = value;
this.leftCount = 0;
this.rightCount = 0;
this.C = C;
}
public int getValue()
{
return this.value;
}
public Node getRight()
{
return this.rightChild;
}
public Node getLeft()
{
return this.leftChild;
}
//public Node insert(Node t, Node newOne) -- t is the root?
public void insert(Node root, Node prev, Node curr)
{
if(C.getColor(prev.value,curr.value)) //color 1
{
if(root.leftChild!=null)
{
insert(root.leftChild,prev,curr);
}
else
{
root.leftChild = curr;
leftCount++;
}
}
else
{
if(root.rightChild!=null)
{
insert(root.rightChild,prev,curr);
}
else
{
root.rightChild = curr;
rightCount++;
}
}
//derpface
/*System.out.println("inserting: "+t+", "+newOne);
if(t.root == null)
{
System.out.println("root created: "+t);
t.root = t;
leftCount++;
rightCount++;
return newOne;
}
else if(C.getColor(t.value,newOne.value))
{
System.out.println("inserting left: "+t);
leftCount++;
t.leftChild = t;
insert(t.leftChild, newOne);
return t;
}
else
{
System.out.println("inserting right: "+t);
rightCount++;
t.rightChild = t;
insert(t.rightChild, newOne);
return t;
}*/
}
@Override
public String toString()
{
return Integer.toString(this.value);
}
}