public class RBCell<T extends Comparable> extends Cell<T>
It is a pure implementation class. For harnesses, see:
For an introduction to this package see Overview .
RBTree
,
Serialized FormModifier and Type | Field and Description |
---|---|
protected boolean |
color_
The node color (RED, BLACK)
|
protected RBCell |
left_
Pointer to left child
|
protected RBCell |
right_
Pointer to right child
|
Constructor and Description |
---|
RBCell(T element)
Make a new cell with given element, null links, and BLACK color.
|
Modifier and Type | Method and Description |
---|---|
int |
count(T element)
Return number of nodes of current subtree containing element.
|
RBCell |
delete(RBCell root)
Delete the current node, and then rebalance the tree it is in
|
RBCell |
find(T element)
Return node of current subtree containing element as element(),
if it exists, else null.
|
protected RBCell |
fixAfterDeletion(RBCell root)
From CLR
|
protected RBCell |
fixAfterInsertion(RBCell root)
From CLR
|
RBCell |
insertLeft(RBCell cell,
RBCell root)
There's no generic element insertion.
|
RBCell |
insertRight(RBCell cell,
RBCell root)
Insert cell as the right child of current node, and then
rebalance the tree it is in.
|
boolean |
isRoot()
Return true if node is a root (i.e., has a null parent)
|
RBCell |
left()
Return left child (or null)
|
RBCell |
leftmost()
Return the minimum element of the current (sub)tree
|
RBCell |
parent()
Return parent (or null)
|
RBCell<T> |
predecessor()
Return the inorder predecessor, or null if no such
|
RBCell |
right()
Return right child (or null)
|
RBCell |
rightmost()
Return the maximum element of the current (sub)tree
|
RBCell |
root()
Return the root (parentless node) of the tree
|
protected RBCell |
rotateLeft(RBCell root)
From CLR
|
protected RBCell |
rotateRight(RBCell root)
From CLR
|
int |
size()
Return the number of nodes in the subtree
|
RBCell<T> |
successor()
Return the inorder successor, or null if no such
|
RBCell<T> |
treeMaximum() |
RBCell<T> |
treeMinimum()
Searches a node with smallest key starting from the node x which is usually the root.
|
protected boolean color_
public final boolean isRoot()
public final RBCell<T> predecessor()
public final int size()
public RBCell find(T element)
public int count(T element)
public RBCell insertLeft(RBCell cell, RBCell root)
Insert cell as the left child of current node, and then rebalance the tree it is in.
cell
- the cell to addroot,
- the root of the current treepublic RBCell insertRight(RBCell cell, RBCell root)
cell
- the cell to addroot,
- the root of the current treepublic RBCell delete(RBCell root)
root
- the root of the current treepublic RBCell<T> treeMinimum()
x
- The node from which to start, usually the root.NullPointerException
- If the parameter x is null.public RBCell<T> treeMaximum()
protected final RBCell rotateLeft(RBCell root)
protected final RBCell rotateRight(RBCell root)
protected final RBCell fixAfterInsertion(RBCell root)
protected final RBCell fixAfterDeletion(RBCell root)