Package edu.ksu.cis.viewer
Class RedBlackTree
java.lang.Object
edu.ksu.cis.viewer.RedBlackTree
- All Implemented Interfaces:
BSTInterface
,Serializable
An immutable red-black tree that can draw itself. A red-black tree is
a binary search tree with the following properties:
- Each node is colored either red or black.
- The root is black.
- If an internal node is red, its parent is black.
- For every empty subtree, the number of black proper ancestors is the same.
- Author:
- Rod Howell (rhowell@ksu.edu)
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()
Because this structure is immutable, this method simply returns this tree.Returns a drawing of this tree.getDrawing
(Font fnt) Returns a drawing of this tree using the given Font.Returns theRedBlackTree
resulting from the insertion ofkey
into thisRedBlackTree
.Returns theRedBlackTree
resulting from the removal ofkey
from thisRedBlackTree
.
-
Constructor Details
-
RedBlackTree
public RedBlackTree()Constructs an empty RedBlackTree.
-
-
Method Details
-
put
Returns theRedBlackTree
resulting from the insertion ofkey
into thisRedBlackTree
. Ifkey
is already in this tree, an identical tree is returned.- Specified by:
put
in interfaceBSTInterface
- Parameters:
key
- the key to insert- Returns:
- the resutling tree
- Throws:
NullPointerException
- Ifkey
isnull
-
remove
Returns theRedBlackTree
resulting from the removal ofkey
from thisRedBlackTree
. Ifkey
is not in this tree, an identical tree is returned.- Specified by:
remove
in interfaceBSTInterface
- Parameters:
key
- the key to remove- Returns:
- the resulting tree
- Throws:
NullPointerException
- If key isnull
-
getDrawing
Returns a drawing of this tree.- Specified by:
getDrawing
in interfaceBSTInterface
- Returns:
- a drawing of the tree
-
getDrawing
Returns a drawing of this tree using the given Font.- Specified by:
getDrawing
in interfaceBSTInterface
- Parameters:
fnt
- the font to use- Returns:
- a drawing of the tree
- Throws:
NullPointerException
- iffnt
isnull
.
-
clone
Because this structure is immutable, this method simply returns this tree.- Specified by:
clone
in interfaceBSTInterface
- Overrides:
clone
in classObject
- Returns:
- a clone of the this tree
-