-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRBTreeNode.java
executable file
·175 lines (158 loc) · 4.83 KB
/
RBTreeNode.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/**
* The class RBTreeNode is an abstract Node implementation for the RBTree class
* @author Juhani Seppälä
*
*/
public class RBTreeNode<E> {
private E element;
private RBTreeNode<E> parent;
private RBTreeNode<E> leftChild;
private RBTreeNode<E> rightChild;
private int color; // 0 = r, 1 = b
private boolean sentinel;
/**
* The empty constructor for the class RBTreeNode constructs a new sentinel-node with the color set to black
* and the sentinel-flag set to true
* @param element Solmun hyötytiedoksi tuleva data
* @author Juhani Seppälä
*
*/
public RBTreeNode() {
sentinel = true;
color = 1;
}
/**
* The constructor for the class RBTreeNode, given an element, constructs a new node with the parameter-given
* element, the sentinel-flag set to false and the default color of red
* @param element Solmun hyötytiedoksi tuleva data
* @author Juhani Seppälä
*
*/
public RBTreeNode(E element) {
this.element = element;
this.sentinel = false;
}
/**
* Luokan RBTreeNode konstruktori muodostaa parametrina saadusta objektista uuden
* solmun
* The constructor for the class RBTreeNode, given an element, parent, left child node, right child node and the color, constructs a new node
* with all the parameter-given values as its attributes and the sentinel flag set to false
* @author Juhani Seppälä
* @param element Solmun hyötytiedoksi tuleva data
*
*/
public RBTreeNode(E element,
RBTreeNode<E> parent,
RBTreeNode<E> leftChild,
RBTreeNode<E> rightChild,
int color) {
this.element = element;
this.parent = parent;
this.leftChild = leftChild;
this.rightChild = rightChild;
this.color = color;
this.sentinel = false;
}
/**
* The method getElement returns the element of this node
* @return The element of this node
* @author Juhani Seppälä
*/
public E getElement() {
return element;
}
/**
* The method getLeftChild returns the left child of this node
* @return The left child of this node, or null, if no left child exists
* @author Juhani Seppälä
*
*/
public RBTreeNode<E> getLeftChild() {
return leftChild;
}
/**
* The method getRightChild returns the left child of this node
* @return The right child of this node, or null, if no right chil exists
* @author Juhani Seppälä
*
*/
public RBTreeNode<E> getRightChild() {
return rightChild;
}
/**
* The method parent return the parent of this node
* @return The parent of this node, or null, if no parent node exists
* @author Juhani Sepäälä
*/
public RBTreeNode<E> getParent() {
return parent;
}
/**
* The method setElement sets the parameter-given element as the element of this node
* @param The element to be set as the element of this node
* @author Juhani Seppälä
*
*/
public void setElement(E element) {
this.element = element;
}
/**
* The method setLeftChild set the parameter-given node as the left child of this node
* @param node The node to be set as the left child of this node
*
*/
public void setLeftChild(RBTreeNode<E> node) {
leftChild = node;
}
/**
* The method setRightChild sets the parameter-given node as the right child of this node
* @param node The node to be set as the right child of this node
*
*/
public void setRightChild(RBTreeNode<E> node) {
rightChild = node;
}
/**
* The method setParent sets the parameter-given node as the parent of this node
* @param node The node to be added as the parent of this node
*
*/
public void setParent(RBTreeNode<E> node) {
parent = node;
}
/**
* The method setColor sets the parameter-given color as the color of this node
* @param color The color to be set as the color of this node (0 = red, 1 = black)
*
*/
public void setColor(int color) {
this.color = color;
}
/**
* The method getColor returns the color of this node
* @return The color of this node (0 = red, 1 = black)
*
*/
public int getColor() {
return color;
}
/**
* The method setSentinel sets the parameter-given sentinel-flaq as the sentinel-flag of this node
* @author Juhani Seppälä
*/
public void setSentinel(boolean sentinel) {
this.sentinel = sentinel;
}
/**
* The method
*/
public boolean getSentinel() {
return sentinel;
}
public String toString() {
if (element != null)
return String.valueOf(element);
else
return "-";
}
} // class