Package edu.ksu.cis.viewer
Class BinarySearchTree
java.lang.Object
edu.ksu.cis.viewer.BinarySearchTree
- All Implemented Interfaces:
BSTInterface
,Serializable
An immutable binary search tree that can draw itself.
- 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 theBinarySearchTree
resulting from the insertion ofkey
into thisBinarySearchTree
.Returns theBinarySearchTree
resulting from the removal ofkey
from thisBinarySearchTree
.
-
Constructor Details
-
BinarySearchTree
public BinarySearchTree()Constructs an empty BinarySearchTree.
-
-
Method Details
-
put
Returns theBinarySearchTree
resulting from the insertion ofkey
into thisBinarySearchTree
. 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 theBinarySearchTree
resulting from the removal ofkey
from thisBinarySearchTree
. 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
- Ifkey
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
-