|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--BSTTree | +--BSTTreeHead | +--SplayTreeHead
This class provides the head structure for a SplayBSTTree
. It extends the
object RootInsertionBSTTreeHead
because it is root inserted, just a splay
instead of a rotate to top. Therefore, it overides all important methods necessary for maintaining a
Splay Tree.
Nested Class Summary |
Nested classes inherited from class BSTTreeHead |
BSTTreeHead.NodeAndKey |
Field Summary | |
static java.lang.String |
TREE_INFORMATION
String representing information regarding the type of tree. |
Fields inherited from class BSTTreeHead |
BINARY_DISPLAY, SECTIONAL_DISPLAY |
Fields inherited from class BSTTree |
ANIMATING_BST_TREE_TYPE, BST_TREE_TYPE, DRAWING_BST_TREE_TYPE |
Fields inherited from interface TreeHead |
BALANCE_NODE, CHANGE_DISPLAY, INORDER_TRAVERSAL, INSERT_NODE, LEVELORDER_TRAVERSAL, PARTITION_NODE, POSTORDER_TRAVERSAL, PREORDER_TRAVERSAL, REMOVE_NODE, ROTATE_TO_TOP_NODE, ROTATE_UP, ROTATE_UP_DOUBLE, SEARCH, SELECT, SPLAY_NODE, TRAVERSE |
Constructor Summary | |
SplayTreeHead()
Constructs a new, null RootInsertionBSTTreeHead, sorted according to the keys' natural order and insertion occurs automatically to the root. |
|
SplayTreeHead(int treeType)
Constructs a new, empty RootInsertionBSTTreeHead according to the type passed. |
Method Summary | |
double |
averageInsertion(int n)
Returns the average Insertion time, according to n, the amount of elements in the tree. |
java.lang.String |
getTreeTypeString()
Gets the tree type String for the BSTTree. |
void |
insert(Tree node)
Adds the node to the tree using its natural ordering . |
protected void |
insertAnimatingType(BSTTree node)
Insert the comaparable node to the tree using its natural ordering . |
Tree |
search(java.lang.Comparable keySearch)
Searches for the comaparable object in the Tree using its natural ordering . |
void |
waitingAction(java.lang.String action,
java.lang.Object element)
Acts according to the String action passed.Overides BSTTree, to stop rapid-fire insertion. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface Tree |
getChildren, getKey, getLevel, getParentTree, getValue, isEmpty |
Field Detail |
public static final java.lang.String TREE_INFORMATION
Constructor Detail |
public SplayTreeHead()
Default type is BST_TREE_TYPE.
public SplayTreeHead(int treeType)
treeType
- type of tree that should be implemented.Method Detail |
public java.lang.String getTreeTypeString()
getTreeTypeString
in class BSTTree
public double averageInsertion(int n)
averageInsertion
in class BSTTreeHead
n
- the size of the tree for which the average search hit is needed.
public void waitingAction(java.lang.String action, java.lang.Object element)
waitingAction
in interface TreeHead
waitingAction
in class BSTTreeHead
action
- String action representing the next action for the BSTTreeHead.element
- element to which the action could be occuring, depending on the type of action.public void insert(Tree node) throws java.lang.ClassCastException
The new node is inserted and then rotateToToped to the root. This defines the tree as a rotateToTop BSTTree.
insert
in class BSTTreeHead
node
- BSTTree which is added to the tree.
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.public Tree search(java.lang.Comparable keySearch) throws java.lang.ClassCastException, java.lang.NullPointerException
Tree
using its natural ordering .
If the method is successful in finding the element, the item is returned. Otherwise, the closest item is
returned.
The found node rotated to the top, to the root. If the node is not found, the nearest node is rotated to the top.
search
in interface TreeHead
search
in class BSTTreeHead
keySearch
- comparable object which is search for within the tree.
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.
java.lang.NullPointerException
- key is null.protected void insertAnimatingType(BSTTree node) throws java.lang.ClassCastException
Makes insert
a waitingAction if the tree is animating.
insertAnimatingType
in class BSTTreeHead
node
- BSTTree node to be inserted into the tree
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |