|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--com.mhhe.clrs2e.BinarySearchTree
|
+--com.mhhe.clrs2e.RedBlackTree
Implements the Dictionary interface as a red-black tree
from Chapter 13 of Introduction to Algorithms, Second
edition. Objects inserted into a red-black tree must implement the
Comparable interface.
| Nested Class Summary | |
static class |
RedBlackTree.BlackHeightException
Exception thrown by blackHeight(com.mhhe.clrs2e.RedBlackTree.Node) if the black-height of
a node is ill-defined. |
protected class |
RedBlackTree.Node
Inner class for a red-black tree node. |
| Nested classes inherited from class com.mhhe.clrs2e.BinarySearchTree |
BinarySearchTree.Visitor |
| Field Summary | |
protected static java.awt.Color |
BLACK
Color for a black node. |
protected static java.awt.Color |
RED
Color for a red node. |
| Fields inherited from class com.mhhe.clrs2e.BinarySearchTree |
nil, root |
| Constructor Summary | |
RedBlackTree()
Creates a red-black tree with just a nil, which is
the root. |
|
| Method Summary | |
int |
blackHeight()
Returns the number of black nodes from the root down to any leaf. |
int |
blackHeight(RedBlackTree.Node z)
Returns the number of black nodes from a given node down to any leaf. |
void |
delete(java.lang.Object handle)
Removes a node from the tree. |
protected void |
deleteFixup(RedBlackTree.Node x)
Restores the red-black properties of the tree after a deletion. |
java.lang.Object |
insert(java.lang.Comparable data)
Inserts data into the tree, creating a new node for this data. |
protected void |
insertFixup(RedBlackTree.Node z)
Restores the red-black conditions of the tree after inserting a node. |
protected void |
leftRotate(RedBlackTree.Node x)
Performs a left rotation on a node, making the node's right child its parent. |
protected void |
rightRotate(RedBlackTree.Node x)
Performs a right rotation on a node, making the node's left child its parent. |
protected void |
setNil(RedBlackTree.Node node)
Set the sentinel nil to a given node, and make the
sentinel black. |
protected void |
treeInsert(RedBlackTree.Node z)
Inserts a node into the tree. |
| Methods inherited from class com.mhhe.clrs2e.BinarySearchTree |
dereference, inorderWalk, inorderWalk, isNil, iterativeSearch, maximum, minimum, postorderWalk, postorderWalk, predecessor, preorderWalk, preorderWalk, search, search, setNil, successor, toString, treeInsert, treeMaximum, treeMinimum |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
protected static final java.awt.Color RED
protected static final java.awt.Color BLACK
| Constructor Detail |
public RedBlackTree()
nil, which is
the root.
| Method Detail |
protected void setNil(RedBlackTree.Node node)
nil to a given node, and make the
sentinel black.
node - The node that nil is set to.protected void leftRotate(RedBlackTree.Node x)
x - The node.protected void rightRotate(RedBlackTree.Node x)
x - The node.public java.lang.Object insert(java.lang.Comparable data)
insert in interface Dictionaryinsert in class BinarySearchTreedata - Data to be inserted into the tree.
Node object created.
The Node class is opaque to methods outside this
class.protected void treeInsert(RedBlackTree.Node z)
z - The node to insert.protected void insertFixup(RedBlackTree.Node z)
z - The node inserted.public void delete(java.lang.Object handle)
delete in interface Dictionarydelete in class BinarySearchTreehandle - The node to be removed.
DeleteSentinelException - if there is an attempt to
delete the sentinel nil.
java.lang.ClassCastException - if node does not
reference a Node object.protected void deleteFixup(RedBlackTree.Node x)
x - Node at which there may be a violation.public int blackHeight(RedBlackTree.Node z)
z - The node.
RedBlackTree.BlackHeightException - if the number of black nodes on a
path from the left child down to a leaf differs from the number
of black nodes on a path from the right child down to a leaf.public int blackHeight()
RedBlackTree.BlackHeightException - if the number of black nodes on a
path from the left child down to a leaf differs from the number
of black nodes on a path from the right child down to a leaf.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||