Package edu.ksu.cis.viewer
Class SplayTree
java.lang.Object
edu.ksu.cis.viewer.SplayTree
- All Implemented Interfaces:
BSTInterface
,Serializable
An immutable splay tree that can draw itself. A splay tree is
self-adjusting in the sense that the deepest node accessed on any operation
is brought to the root. By using double rotations whenever possible,
logarathmic amortized peformance is achieved. This implementation is
top-down. As a result, if a single rotation must occur, it occurs at
the lowest point in the path traversed.
- 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 the tree resulting from the insert of the given key.Returns the tree resulting from the removal of the given key.
-
Constructor Details
-
SplayTree
public SplayTree()Constructs an empty SplayTree.
-
-
Method Details
-
put
Returns the tree resulting from the insert of the given key. Ifkey
is already in the tree, a tree having the same contents withkey
at the root is returned.- Specified by:
put
in interfaceBSTInterface
- Parameters:
key
- the key to insert- Returns:
- the resutling tree
- Throws:
NullPointerException
- Ifkey
isnull
-
remove
Returns the tree resulting from the removal of the given key. If the key is not in the tree, a tree having the same contents 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
-