Package edu.ksu.cis.viewer
Class AVLTree
java.lang.Object
edu.ksu.cis.viewer.AVLTree
- All Implemented Interfaces:
BSTInterface
,Serializable
An immutable AVL tree that can draw itself. An AVL tree is a binary
search tree such that if it is nonempty, its children differ in height
by at most 1.
- 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 theAVLTree
resulting from the insertionkey
into thisAVLTree
.Returns theAVLTree
resulting from the removal ofkey
from thisAVLTree
.
-
Constructor Details
-
AVLTree
public AVLTree()Constructs an empty AVLTree.
-
-
Method Details
-
put
Returns theAVLTree
resulting from the insertionkey
into thisAVLTree
. 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 theAVLTree
resulting from the removal ofkey
from thisAVLTree
. 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
-