Package edu.ksu.cis.viewer
Class AATree
java.lang.Object
edu.ksu.cis.viewer.AATree
- All Implemented Interfaces:
BSTInterface
,Serializable
An immutable AA tree that can draw itself. An AA tree is a binary
search tree in which each node has a level and a color, either red or
black. The level of any leaf is 1, and the level of any non-leaf is one
greater than the level of its left child (if it has one), and either equal
to or one greater than the level of its right child (if it has one). A node
is considered to be red if it has the same level as its parent; otherwise,
it is considered to be black (the root is always black). The parent
of a red node must always be black.
- Author:
- Stella Houston and Rod Howell (rhowell@ksu.edu)
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()
Returns a clone of this tree.Returns a drawing of the tree.getDrawing
(Font fnt) Returns a drawing of the tree using the given Font.Returns theAATree
resulting from the insertionkey
into thisAATree
.Returns theAATree
resulting from the removal ofkey
from thisAATree
.
-
Constructor Details
-
AATree
public AATree()Constructs an empty AA Tree.
-
-
Method Details
-
put
Returns theAATree
resulting from the insertionkey
into thisAATree
. Ifkey
is already in the 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 theAATree
resulting from the removal ofkey
from thisAATree
. Ifkey
is not in the 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 the tree.- Specified by:
getDrawing
in interfaceBSTInterface
- Returns:
- a drawing of the tree
-
getDrawing
Returns a drawing of the 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
Returns a clone of this tree.- Specified by:
clone
in interfaceBSTInterface
- Overrides:
clone
in classObject
- Returns:
- a clone of this tree
-