|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.princeton.cs.algs4.growingtree.framework.GrowingTreeNode<P>
edu.princeton.cs.algs4.growingtree.framework.GrowingTreeHead<P>
public class GrowingTreeHead<P extends NodeProperties>
This class provides the head structure for a BSTTree
. It implements the
interface for TreeHead and implements all important methods necessary for maintaining a
Binary Search Tree.
The BSTTreeHead additionally extends BSTTree, using the information and methods of a
BSTTree in addition to the specialized methods of a BSTTreeHead.
Field Summary | |
---|---|
static int |
BINARY_DISPLAY
Binary Display |
static int |
SECTIONAL_DISPLAY
sectional display |
static java.lang.String |
TREE_INFORMATION
String representing information regarding the type of tree. |
Fields inherited from class edu.princeton.cs.algs4.growingtree.framework.GrowingTreeNode |
---|
ANIMATING_BST_TREE_TYPE, BST_TREE_TYPE, DRAWING_BST_TREE_TYPE |
Fields inherited from interface edu.princeton.cs.algs4.growingtree.framework.TreeHead |
---|
BALANCE_NODE, CHANGE_DISPLAY, FREEZE, 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, SWAP, TRAVERSE |
Constructor Summary | |
---|---|
GrowingTreeHead()
Constructs a new, null BSTTreeHead, sorted according to the keys' natural order. |
|
GrowingTreeHead(int treeType)
Constructs a new, empty BSTTree according to the type passed. |
|
GrowingTreeHead(P np,
IInsertOperator<P> inserter,
ISearchOperator<P> searcher,
IDeleteOperator<P> deleter,
TreeJPanel<P> panel)
|
|
GrowingTreeHead(P np,
IInsertOperator<P> inserter,
ISearchOperator<P> searcher,
IDeleteOperator<P> deleter,
TreeJPanel<P> panel,
IExperimentLogger<P> logger)
|
Method Summary | |
---|---|
void |
addTreeAnimator(Animation a)
Adds the Animation to the list of Animations for the Head. |
void |
addTreeMessageListener(TreeMessageListener l)
Adds an TreeMessageListener from the TREE, according to the TreeMessageListener interface and the TreeMessageEvent . |
void |
AnimateTree(java.awt.Graphics2D g2)
Animates the entire BSTTree. |
void |
animationEventPerformed(AnimationEvent e)
Implements AnimationListener which requires the following method. |
double |
averageInsertion(int n)
Returns the average Insertion time, according to n, the amount of elements in the tree. |
double |
averageSearchHit(int n)
Returns the average Search hit time, according to n, the amount of elements in the tree. |
double |
averageSearchMiss(int n)
Returns the average Search miss time, according to n, the amount of elements in the tree. |
void |
balance(Tree<P> node)
Balances the tree, from the node downward, recursively rotating the median to the top. |
void |
balanceAnimatingType(GrowingTreeNode<P> node)
Balances the tree from the given node, recursively rotating the median to the top. |
void |
balanceTree()
Balances the entire tree, recursively rotating the median to the top. |
void |
balanceTreeType(GrowingTreeNode<P> node)
Balances the tree from the given node, recursively rotating the median to the top. |
void |
changeDisplay()
Changes the display of the current tree. |
void |
changeDisplayAnimatingType()
Change Display of the BSTTree . |
void |
changeDisplayTreeType()
Change Display of the BSTTree . |
void |
clear()
Clears the BSTTree completely, removing all references to all nodes and all values return to the default. |
void |
clearAnimators()
Clears the Animation s from the list of Animations for the Head. |
void |
constructAnimatingBSTTreeHead()
Constructor for the ANIMATING_BST_TREE_TYPE. |
void |
constructBSTTreeHead()
Constructor for the BST_TREE_TYPE. |
void |
constructDrawingBSTTreeHead()
Constructor for the DRAWING_BST_TREE_TYPE. |
void |
delete(Tree<P> node,
boolean successorSwap)
Removes the given node from the tree. |
void |
DrawTree(java.awt.Graphics2D g2)
Draws the entire tree from the null head down. |
DrawingTree<P> |
findNode(double x,
double y)
Finds the node represented by the x-y coordinates given. |
void |
fixLevel()
Fixes the lowest level of the Tree , using recursive calls into the BSTTree. |
int |
fixSize()
Fixes the size of each subtree, using recursive calls into the BSTTree. |
void |
freeze(double lengthMult)
|
void |
freezeAnimatingType(double lengthMult)
|
Tree<P> |
getChild()
Gets the child of the TreeHead. |
PaintSettings |
getDeleteLeftLinePaintSettings()
Gets the Paint for the left line of Paint. |
PaintSettings |
getDeleteRightLinePaintSettings()
Gets the Paint for the right line of Paint. |
int |
getDisplay()
Gets the display choice for the tree. |
KeySettings |
getDrawingKeySettings()
Gets the KeySettings for the entire tree. |
NodeSettings |
getDrawingNodeSettings()
Gets the NodeSettings for the entire tree. |
java.util.LinkedList<GrowingTreeNode<P>> |
getInorderTree()
Makes a inorder representation of the tree in an array of BSTTree s. |
KeySettings |
getInsertAnimatorKeySettings()
Gets the KeySettings for the animator key settings for insertion. |
NodeSettings |
getInsertAnimatorNodeSettings()
Gets the NodeSettings for the animator node settings for insertion. |
NodeSettings |
getInsertNodeLeftSettings()
Gets the NodeSettings for the left node settings for insertion. |
NodeSettings |
getInsertNodeRightSettings()
Gets the NodeSettings for the right node settings for insertion. |
java.util.LinkedList<GrowingTreeNode<P>> |
getLevelorderTree()
Makes a levelorder representation of the tree in an array of BSTTree s. |
IExperimentLogger<P> |
getLogger()
BST_TREE_TYPE Accessor methods * |
double |
getNodeHeight()
Gets the height of the standard node within the tree. |
double |
getNodeWidth()
Gets the width of the standard node within the tree. |
java.util.LinkedList<GrowingTreeNode<P>> |
getPostorderTree()
Makes a postorder representation of the tree in an array of BSTTree s. |
java.util.LinkedList<GrowingTreeNode<P>> |
getPreorderTree()
Makes a preorder representation of the tree in an array of BSTTree s. |
int |
getPreviousDisplay()
Gets the previous display choice for the tree. |
KeySettings |
getRotateAnimatorKeySettings()
Gets the KeySettings for the animator key settings for rotation. |
NodeSettings |
getRotateChildNodeSettings()
Gets the NodeSettings for the child node settings for rotation. |
NodeSettings |
getRotateDescendantNodeSettings()
Gets the NodeSettings for the descendant node settings for rotation. |
KeySettings |
getRotateOriginalKeySettings()
Gets the KeySettings for the original key settings for rotation. |
NodeSettings |
getRotateOriginalNodeSettings()
Gets the NodeSettings for the original node settings for rotation. |
NodeSettings |
getRotateRootNodeSettings()
Gets the NodeSettings for the root node settings for rotation. |
java.awt.geom.Rectangle2D |
getScreenBounds()
Gets the bounds of the screen to which the tree is drawing. |
KeySettings |
getSearchAnimatorKeySettings()
Gets the KeySettings for the animator key settings for searching. |
NodeSettings |
getSearchAnimatorNodeSettings()
Gets the NodeSettings for the animator node settings for searching. |
NodeSettings |
getSearchNodeLeftSettings()
Gets the NodeSettings for the left node settings for searching. |
NodeSettings |
getSearchNodeRightSettings()
Gets the NodeSettings for the right node settings for searching. |
KeySettings |
getSelectAnimatorKeySettings()
Gets the KeySettings for the animator key settings for selection. |
NodeSettings |
getSelectAnimatorNodeSettings()
Gets the NodeSettings for the animator node settings for selection. |
NodeSettings |
getSelectNodeLeftSettings()
Gets the NodeSettings for the left node settings for selection. |
NodeSettings |
getSelectNodeRightSettings()
Gets the NodeSettings for the right node settings for selection. |
boolean |
getSubtreeCountsVisible()
|
KeySettings |
getTraverseAnimatorKeySettings()
Gets the KeySettings for the animator key settings for traversal. |
NodeSettings |
getTraverseAnimatorNodeSettings()
Gets the NodeSettings for the animator node settings for traversal. |
int |
getTreeAnimationStepSize()
Gets the step size of the Animation s of the tree. |
Animation |
getTreeAnimator()
Gets the first Animation in the list of Animations for the Head and null if no
Animations are present. |
int |
getTreeLevel()
Gets the lowest level of the Tree. |
java.lang.String |
getTreeStatus()
Gets the Tree's status, using the String status of Animation . |
java.lang.String |
getTreeStatusMessage()
Makes a new tree message. |
boolean |
insert(KeyType keyInsert,
java.lang.Object valueInsert)
Inserts the comaparable object keyInsert to the tree using its natural ordering . |
void |
insert(Tree<P> node)
Inserts the node to the tree using its natural ordering . |
boolean |
isJumpStep()
Gets the JumpStep of the current tree. |
boolean |
isStepPause()
Gets the StepPause of the current tree. |
boolean |
isTreeAnimating()
Returns true if the current AnimatingBSTTreeHead is animating (whether the animating list is empty. |
boolean |
isTreeEmpty()
Returns true if the TreeHead is empty, indicating no Child node, and a level of 0. |
boolean |
isTreeRemove()
Gets whether the AnimatingBSTTreeHead is removing an Animation . |
Animation |
makeBalanceAnimation(GrowingTreeNode<P> node)
Makes a balance Animation using the given node. |
Animation |
makeChangeDisplayAnimation()
Makes a changeDisplay Animation. |
Animation |
makeDeletionAnimation(GrowingTreeNode<P> node)
Makes a deletion Animation using the given node. |
Animation |
makeFreezeAnimation(double lengthMult)
|
Animation |
makeInsertAnimation(GrowingTreeNode<P> insertNode)
Makes an insert Animation using the given node. |
Animation |
makePartitionAnimation(GrowingTreeNode<P> node,
int keySelect)
Makes a partition Animation using the given node and given keySelect. |
Animation |
makeRotationAnimation(GrowingTreeNode<P> node)
Makes a rotation Animation using the given node. |
Animation |
makeRotationDoubleAnimation(GrowingTreeNode<P> node)
Makes a rotationDouble Animation using the given node. |
Animation |
makeSearchAnimation(KeyType keySearch)
Makes a search Animation using the given keySearch. |
Animation |
makeSelectionAnimation(GrowingTreeNode<P> node,
int keySelect)
Makes a select Animation using the given keySelect. |
Animation |
makeSwapNodesAnimation(GrowingTreeNode<P> node,
int keySelect)
|
Animation |
makeTraverseAnimation(java.util.LinkedList<GrowingTreeNode<P>> nodeList)
Makes a traverse Animation using the given LinkedList. |
void |
MakeTree(java.awt.Graphics2D g2)
Makes the entire tree from the null head down. |
int |
maxKeyWidth()
|
Tree<P> |
partition(Tree<P> node,
int keySelect)
Partitions from the given node the keySelect value. |
void |
pause()
Sets the status of the AnimatingBSTTree to pause. |
void |
play()
Sets the status of the AnimatingBSTTree to play. |
void |
popTreeProperties()
|
boolean |
remove(KeyType keyRemove)
Removes the comaparable object keyRemove from the BSTTree using its natural ordering . |
void |
remove(Tree<P> node)
Removes the given node from the tree. |
void |
removeTreeAnimation()
Quickly removes all Animations within the Tree. |
void |
removeTreeMessageListener(TreeMessageListener l)
Removes an TreeMessageListener from the TREE, according to the TreeMessageListener interface and the TreeMessageEvent . |
void |
removeTreeType(GrowingTreeNode<P> node)
Removes the given node from the tree. |
void |
resetTreeLevel()
Resets the lowest level of the Tree . |
void |
rewind()
Sets the status of the AnimatingBSTTree to rewind. |
void |
rotateToTop(GrowingTreeNode<P> node)
Rotates the BSTTTree to the top. |
void |
rotateUp(GrowingTreeNode<P> node)
Rotates the BSTTree up. |
void |
rotateUp(GrowingTreeNode<P> node,
int levelCount)
Rotates the BSTTree up. |
void |
rotateUpDouble(GrowingTreeNode<P> node)
Double Rotatation of the BSTTTree . |
void |
rotateUpDouble(GrowingTreeNode<P> node,
int levelCount)
Doubly Rotates the BSTTree up to the top. |
void |
rotateUpDoubleTreeType(GrowingTreeNode<P> node)
Double Rotates the BSTTree up. |
void |
rotateUpTreeType(GrowingTreeNode<P> node)
Rotates the BSTTree up. |
void |
saveTreeProperties()
ANIMATING_BST_TREE_TYPE Mutator methods * |
Tree<P> |
search(KeyType keySearch)
Searches for the comaparable object in the Tree using its natural ordering . |
Tree<P> |
searchTreeType(KeyType keySearch)
Searches for the Tree in the entire tree. |
Tree<P> |
select(Tree<P> node,
int keySelect)
Selects the kth smallest item in the Tree using its natural ordering from the given node. |
Tree<P> |
selectTreeType(GrowingTreeNode<P> node,
int keySelect)
Selects for the Tree in the entire tree. |
void |
setChild(Tree<P> child)
Sets the child of the TreeHead. |
void |
setDeleteLeftLinePaintSettings(PaintSettings p)
Sets the PaintSettings for the left line of Paint. |
void |
setDeleteRightLinePaintSettings(PaintSettings p)
Sets the PaintSettings for the right line of Paint. |
void |
setDisplay(int display)
Sets the display choice for the tree. |
void |
setDrawingKeySettings(KeySettings k)
Sets the KeySettings for the key of the head, used in creation of new nodes. |
void |
setDrawingNodeSettings(NodeSettings s)
Sets the NodeSettings for the node of the head, used in creation of new nodes. |
void |
setInsertAnimatorKeySettings(KeySettings k)
Sets the KeySettings for the animator key settings for insertion. |
void |
setInsertAnimatorNodeSettings(NodeSettings n)
Sets the NodeSettings for the animator node settings for insertion. |
void |
setInsertNodeLeftSettings(NodeSettings n)
Sets the NodeSettings for the left node settings for insertion. |
void |
setInsertNodeRightSettings(NodeSettings n)
Sets the NodeSettings for the right node settings for insertion. |
void |
setJumpStep(boolean b)
Sets the JumpStep of the current tree to the boolean value. |
void |
setPreviousDisplay(int previousDisplay)
Sets the previous display choice for the tree. |
void |
setRotateAnimatorKeySettings(KeySettings k)
Sets the KeySettings for the animator key settings for rotation. |
void |
setRotateChildNodeSettings(NodeSettings n)
Sets the NodeSettings for the child node settings for rotation. |
void |
setRotateDescendantNodeSettings(NodeSettings n)
Sets the NodeSettings for the descendant node settings for rotation. |
void |
setRotateOriginalKeySettings(KeySettings k)
Sets the KeySettings for the original key settings for rotation. |
void |
setRotateOriginalNodeSettings(NodeSettings n)
Sets the NodeSettings for the original node settings for rotation. |
void |
setRotateRootNodeSettings(NodeSettings n)
Sets the NodeSettings for the root node settings for rotation. |
void |
setScreenBounds(java.awt.geom.Rectangle2D screen)
Sets the bounds of the screen to which the tree is drawing. |
void |
setSearchAnimatorKeySettings(KeySettings k)
Sets the KeySettings for the animator key settings for searching. |
void |
setSearchAnimatorNodeSettings(NodeSettings n)
Sets the NodeSettings for the animator node settings for searching. |
void |
setSearchNodeLeftSettings(NodeSettings n)
Sets the NodeSettings for the left node settings for searching. |
void |
setSearchNodeRightSettings(NodeSettings n)
Sets the NodeSettings for the right node settings for searching. |
void |
setSelectAnimatorKeySettings(KeySettings k)
Sets the KeySettings for the animator key settings for selection. |
void |
setSelectAnimatorNodeSettings(NodeSettings n)
Sets the NodeSettings for the animator node settings for selection. |
void |
setSelectNodeLeftSettings(NodeSettings n)
Sets the NodeSettings for the left node settings for selection. |
void |
setSelectNodeRightSettings(NodeSettings n)
Sets the NodeSettings for the right node settings for selection. |
void |
setStepPause(boolean b)
Sets the StepPause of the current tree to the boolean value. |
void |
setSubtreeCountsVisible(boolean visible)
BST_TREE_TYPE Mutator methods * |
void |
setTraverseAnimatorKeySettings(KeySettings k)
Sets the KeySettings for the animator key settings for traversal. |
void |
setTraverseAnimatorNodeSettings(NodeSettings n)
Sets the NodeSettings for the animator node settings for traversal. |
void |
setTreeAnimationsStepSize(int t)
Sets the step size of the Animation s of the tree. |
void |
setTreeSettings(NodeSettings s,
KeySettings k)
Sets the NodeSettings for the entire tree from the head down. |
void |
setTreeStatus(java.lang.String s)
Sets the Status of the entire tree, using the status of Animation class. |
void |
setTreeType(int treeType)
Sets the tree type for the BSTTree. |
int |
size()
Returns the number of objects in the entire tree. |
void |
splay(GrowingTreeNode<P> node)
Splays the BSTTTree to the top (Double rotates). |
void |
stop()
Sets the status of the AnimatingBSTTree to stop. |
void |
swapNodes(Tree<P> node,
int keySelect)
Swaps node with the the kth smallest item in its subtree using its natural ordering from the given node. |
void |
swapTreeType(GrowingTreeNode<P> node,
int keySelect)
Selects for the Tree in the entire tree. |
java.util.LinkedList<GrowingTreeNode<P>> |
traverse(int traverseType)
Traverses the tree in the given traversal type. |
java.util.LinkedList<GrowingTreeNode<P>> |
traverseAnimatingType(int traverseType)
Traverses the tree in the given traversal type. |
java.util.LinkedList<GrowingTreeNode<P>> |
traverseTreeType(int traverseType)
Traverses the tree in the given traversal type. |
void |
waitingAction(java.lang.String action,
ActionElementType<P> element)
Acts according to the String action passed. |
double |
worstCaseInsertion(int n)
Returns the worst case Insertion time, according to n, the amount of elements in the tree. |
double |
worstCaseSearchHit(int n)
Returns the worst case Search hit time, according to n, the amount of elements in the tree. |
double |
worstCaseSearchMiss(int n)
Returns the worst case Search miss time, according to n, the amount of elements in the tree. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface edu.princeton.cs.algs4.growingtree.framework.Tree |
---|
getChildren, getKey, getLevel, getParentTree, getValue, isEmpty |
Field Detail |
---|
public static final java.lang.String TREE_INFORMATION
public static final int BINARY_DISPLAY
public static final int SECTIONAL_DISPLAY
Constructor Detail |
---|
public GrowingTreeHead()
Default type is BST_TREE_TYPE.
public GrowingTreeHead(int treeType)
treeType
- type of tree that should be implemented.public GrowingTreeHead(P np, IInsertOperator<P> inserter, ISearchOperator<P> searcher, IDeleteOperator<P> deleter, TreeJPanel<P> panel)
public GrowingTreeHead(P np, IInsertOperator<P> inserter, ISearchOperator<P> searcher, IDeleteOperator<P> deleter, TreeJPanel<P> panel, IExperimentLogger<P> logger)
Method Detail |
---|
public void setTreeType(int treeType)
setTreeType
in class GrowingTreeNode<P extends NodeProperties>
treeType
- setting for the tree.public void addTreeMessageListener(TreeMessageListener l)
TreeMessageEvent
.
addTreeMessageListener
in interface TreeHead<P extends NodeProperties>
l
- the listener added recieves the TreeMessageEvents occuring.public void removeTreeMessageListener(TreeMessageListener l)
TreeMessageEvent
.
removeTreeMessageListener
in interface TreeHead<P extends NodeProperties>
l
- the listener removed from recieving the TreeMessageEvents occuring.public java.lang.String getTreeStatusMessage()
messageAction
with the information
necessary for the tree status. The information presented include :
getTreeStatusMessage
in interface AnimatingTreeHead<P extends NodeProperties>
public double averageSearchHit(int n)
n
- the size of the tree for which the average search hit is needed.
public double averageSearchMiss(int n)
n
- the size of the tree for which the average search hit is needed.
public double worstCaseSearchHit(int n)
n
- the size of the tree for which the worst case search hit is needed.
public double worstCaseSearchMiss(int n)
n
- the size of the tree for which the worst case search hit is needed.
public double averageInsertion(int n)
n
- the size of the tree for which the average search hit is needed.
public double worstCaseInsertion(int n)
n
- the size of the tree for which the worst case search hit is needed.
public void waitingAction(java.lang.String action, ActionElementType<P> element)
WaitingActionList
which keeps the list of actions, and calls the method when
instructed to call the next action.
waitingAction
in interface TreeHead<P extends NodeProperties>
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 constructBSTTreeHead()
public IExperimentLogger<P> getLogger()
public boolean isTreeEmpty()
TreeHead
is empty, indicating no Child node, and a level of 0.
isTreeEmpty
in interface TreeHead<P extends NodeProperties>
TreeHead
is empty.public Tree<P> getChild()
getChild
in interface TreeHead<P extends NodeProperties>
child
- Tree
, beginning the Tree
nodes.public int getTreeLevel()
getTreeLevel
in interface TreeHead<P extends NodeProperties>
Tree
.public int size()
size
in interface Tree<P extends NodeProperties>
size
in interface TreeHead<P extends NodeProperties>
size
in class GrowingTreeNode<P extends NodeProperties>
public boolean getSubtreeCountsVisible()
public void setSubtreeCountsVisible(boolean visible)
public void setChild(Tree<P> child)
setChild
in interface TreeHead<P extends NodeProperties>
child
- Tree
, beginning the Tree
nodes.public void resetTreeLevel()
Tree
. The level is set to 0, so that is can be recalculated, using fixLevel.
resetTreeLevel
in interface TreeHead<P extends NodeProperties>
public void fixLevel()
Tree
, using recursive calls into the BSTTree. Generally, resetTreeLevel
is called before the method.
fixLevel
in interface TreeHead<P extends NodeProperties>
public int fixSize()
public void clear()
clear
in interface TreeHead<P extends NodeProperties>
public boolean insert(KeyType keyInsert, java.lang.Object valueInsert) throws java.lang.NullPointerException, java.lang.ClassCastException
insert
in interface TreeHead<P extends NodeProperties>
keyInsert
- comparable object which is added to the tree.valueInsert
- Object that accompanies keyInsert in the node.
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.
java.lang.NullPointerException
- key is null.public void insert(Tree<P> node) throws java.lang.ClassCastException
node
- BSTTree which is added to the tree.
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.public void delete(Tree<P> node, boolean successorSwap)
node
- the Tree
node to be removed from the tree.successorSwap
- true if hibbard successor delete, false if predecessorpublic void remove(Tree<P> node)
TreeHead
remove
in interface TreeHead<P extends NodeProperties>
node
- the Tree
node to be removed from the tree.public boolean remove(KeyType keyRemove) throws java.lang.ClassCastException, java.lang.NullPointerException
BSTTree
using its natural ordering .
If the method is successful in removing the element, true is returned.
remove
in interface TreeHead<P extends NodeProperties>
keyRemove
- comparable object which is removed from the tree.
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.
java.lang.NullPointerException
- key is null.public void balanceTree()
balanceTree
in interface TreeHead<P extends NodeProperties>
public void balance(Tree<P> node)
balance
in interface TreeHead<P extends NodeProperties>
node
- the node from which the balance occurspublic Tree<P> partition(Tree<P> node, int keySelect)
partition
in interface TreeHead<P extends NodeProperties>
Tree
- which the partition occurs at.keySelect
- integer key selecting the count item.
public Tree<P> search(KeyType 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.
search
in interface TreeHead<P extends NodeProperties>
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.public Tree<P> select(Tree<P> node, int keySelect)
Tree
using its natural ordering from the given node.
If the method is successful in finding the element, the item is returned. Otherwise, null is
returned if the integer is greater than the size.
select
in interface TreeHead<P extends NodeProperties>
Tree
- which the partition occurs at.keySelect
- integer key selecting the count item.
public void swapNodes(Tree<P> node, int keySelect)
Tree
- which the partition occurs at.keySelect
- integer key selecting the count item.public void freeze(double lengthMult)
public void freezeAnimatingType(double lengthMult)
public int maxKeyWidth()
public void rotateUp(GrowingTreeNode<P> node)
BSTTree
up. It simply changes around references, including the
parent reference and the ancestor reference. The rotation upwards replaces the parent with
the node and brings the parent down a level.
node
- BSTTree that rotated upwards.public void rotateUp(GrowingTreeNode<P> node, int levelCount)
BSTTree
up. It simply changes around references, including the
parent reference and the ancestor reference. The rotation upwards replaces the parent with
the node and brings the parent down a level.
node
- BSTTree that rotated upwards.levelCount
- the amount of levels up the node should rotatepublic void rotateUpDouble(GrowingTreeNode<P> node)
BSTTTree
.
node
- BSTTree that is double rotated (bottom rotation first).public void rotateUpDouble(GrowingTreeNode<P> node, int levelCount)
BSTTree
up to the top. This is also referred to as a Splay
and is the basis for a splay tree if the double rotation occurs to the top.
node
- BSTTree that rotated upwards.levelCount
- the amount of levels up the node should rotatepublic void rotateToTop(GrowingTreeNode<P> node)
BSTTTree
to the top.
node
- BSTTree that is rotated to the top.public void splay(GrowingTreeNode<P> node)
BSTTTree
to the top (Double rotates).
node
- BSTTree that is rotated to the top.public void changeDisplay()
public java.util.LinkedList<GrowingTreeNode<P>> traverse(int traverseType)
traverseType
- int defining the given traversal type.public void removeTreeType(GrowingTreeNode<P> node)
node
- the Tree
node to be removed from the tree.public void balanceTreeType(GrowingTreeNode<P> node)
node
- BSTTree that is balanced from.public Tree<P> searchTreeType(KeyType keySearch) throws java.lang.ClassCastException
Tree
in the entire tree.
keySearch
- the comparable key which is searched for within the tree.
Tree
found or null if keySearch was not present within the tree.
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.public Tree<P> selectTreeType(GrowingTreeNode<P> node, int keySelect) throws java.lang.ClassCastException
Tree
in the entire tree.
node
- the node from which the selection takes place.keySelect
- integer key selecting the count item.
Tree
found or null.
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.public void swapTreeType(GrowingTreeNode<P> node, int keySelect) throws java.lang.ClassCastException
Tree
in the entire tree.
node
- the node from which the selection takes place.keySelect
- integer key selecting the count item.
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.public void rotateUpTreeType(GrowingTreeNode<P> node)
BSTTree
up. It simply changes around references, including the
parent reference and the ancestor reference. The rotation upwards replaces the parent with
the node and brings the parent down a level.
node
- BSTTree that rotated upwards.public void rotateUpDoubleTreeType(GrowingTreeNode<P> node)
BSTTree
up.
node
- BSTTree that rotated upwards.public java.util.LinkedList<GrowingTreeNode<P>> traverseTreeType(int traverseType)
traverseType
- int defining the given traversal type.public void changeDisplayTreeType()
BSTTree
.
public java.util.LinkedList<GrowingTreeNode<P>> getPreorderTree()
BSTTree
s.
Changes in the references in the array have no effect upon the tree.
BSTTree
objects that are the preorder representation of the tree.public java.util.LinkedList<GrowingTreeNode<P>> getInorderTree()
BSTTree
s.
Changes in the references in the array have no effect upon the tree.
BSTTree
objects that are the preorder representation of the tree.public java.util.LinkedList<GrowingTreeNode<P>> getPostorderTree()
BSTTree
s.
Changes in the references in the array have no effect upon the tree.
BSTTree
objects that are the preorder representation of the tree.public java.util.LinkedList<GrowingTreeNode<P>> getLevelorderTree()
BSTTree
s.
Changes in the references in the array have no effect upon the tree.
BSTTree
objects that are the preorder representation of the tree.public void constructDrawingBSTTreeHead()
public int getDisplay()
public int getPreviousDisplay()
public NodeSettings getDrawingNodeSettings()
NodeSettings
for the entire tree.
getDrawingNodeSettings
in interface DrawingTreeHead<P extends NodeProperties>
NodeSettings
for defined for the entire tree.public KeySettings getDrawingKeySettings()
KeySettings
for the entire tree.
getDrawingKeySettings
in interface DrawingTreeHead<P extends NodeProperties>
KeySettings
for defined for the entire tree.public double getNodeWidth()
getNodeWidth
in interface DrawingTreeHead<P extends NodeProperties>
public double getNodeHeight()
getNodeHeight
in interface DrawingTreeHead<P extends NodeProperties>
public java.awt.geom.Rectangle2D getScreenBounds()
getScreenBounds
in interface DrawingTree<P extends NodeProperties>
getScreenBounds
in interface DrawingTreeHead<P extends NodeProperties>
getScreenBounds
in class GrowingTreeNode<P extends NodeProperties>
public NodeSettings getInsertNodeLeftSettings()
public NodeSettings getInsertNodeRightSettings()
public NodeSettings getInsertAnimatorNodeSettings()
public KeySettings getInsertAnimatorKeySettings()
public NodeSettings getSearchNodeLeftSettings()
public NodeSettings getSearchNodeRightSettings()
public NodeSettings getSearchAnimatorNodeSettings()
public KeySettings getSearchAnimatorKeySettings()
public NodeSettings getSelectNodeLeftSettings()
public NodeSettings getSelectNodeRightSettings()
public NodeSettings getSelectAnimatorNodeSettings()
public KeySettings getSelectAnimatorKeySettings()
public NodeSettings getRotateRootNodeSettings()
public NodeSettings getRotateChildNodeSettings()
public NodeSettings getRotateDescendantNodeSettings()
public NodeSettings getRotateOriginalNodeSettings()
public KeySettings getRotateAnimatorKeySettings()
public KeySettings getRotateOriginalKeySettings()
public PaintSettings getDeleteLeftLinePaintSettings()
public PaintSettings getDeleteRightLinePaintSettings()
public NodeSettings getTraverseAnimatorNodeSettings()
public KeySettings getTraverseAnimatorKeySettings()
public void setDisplay(int display)
display
- sets the integer that defines the display choice of the tree.public void setPreviousDisplay(int previousDisplay)
display
- sets the integer that defines the display choice of the tree.public void setTreeSettings(NodeSettings s, KeySettings k)
NodeSettings
for the entire tree from the head down.
These settings are used for drawing the node and the links of each given tree.
setTreeSettings
in interface DrawingTreeHead<P extends NodeProperties>
s
- NodeSettings
for use in drawing the entire tree.k
- KeySettings
for use in drawing the keys of the entire tree.public void setDrawingNodeSettings(NodeSettings s)
NodeSettings
for the node of the head, used in creation of new nodes.
s
- NodeSettings
for use in drawing the nodes.public void setDrawingKeySettings(KeySettings k)
KeySettings
for the key of the head, used in creation of new nodes.
k
- KeySettings
for use in drawing the keys.public void setScreenBounds(java.awt.geom.Rectangle2D screen)
getClipBounds
on the Graphics2D passed, however, the bounds
can be set in any way.
setScreenBounds
in interface DrawingTree<P extends NodeProperties>
setScreenBounds
in interface DrawingTreeHead<P extends NodeProperties>
setScreenBounds
in class GrowingTreeNode<P extends NodeProperties>
bounds
- the rectangle representing the bounds of the screen.public void setInsertNodeLeftSettings(NodeSettings n)
public void setInsertNodeRightSettings(NodeSettings n)
public void setInsertAnimatorNodeSettings(NodeSettings n)
public void setInsertAnimatorKeySettings(KeySettings k)
public void setSearchNodeLeftSettings(NodeSettings n)
public void setSearchNodeRightSettings(NodeSettings n)
public void setSearchAnimatorNodeSettings(NodeSettings n)
public void setSearchAnimatorKeySettings(KeySettings k)
public void setSelectNodeLeftSettings(NodeSettings n)
public void setSelectNodeRightSettings(NodeSettings n)
public void setSelectAnimatorNodeSettings(NodeSettings n)
public void setSelectAnimatorKeySettings(KeySettings k)
public void setRotateRootNodeSettings(NodeSettings n)
public void setRotateChildNodeSettings(NodeSettings n)
public void setRotateDescendantNodeSettings(NodeSettings n)
public void setRotateOriginalNodeSettings(NodeSettings n)
public void setRotateAnimatorKeySettings(KeySettings k)
public void setRotateOriginalKeySettings(KeySettings k)
public void setDeleteLeftLinePaintSettings(PaintSettings p)
public void setDeleteRightLinePaintSettings(PaintSettings p)
public void setTraverseAnimatorNodeSettings(NodeSettings n)
public void setTraverseAnimatorKeySettings(KeySettings k)
public void MakeTree(java.awt.Graphics2D g2)
MakeTree
in interface DrawingTreeHead<P extends NodeProperties>
g2
- Graphics2D which the tree is made to fit unto.public void DrawTree(java.awt.Graphics2D g2)
MakeTree
.
DrawTree
in interface DrawingTreeHead<P extends NodeProperties>
g2
- Graphics2D which the tree is drawn onto.public DrawingTree<P> findNode(double x, double y)
findNode
in interface DrawingTreeHead<P extends NodeProperties>
x
- x-coordinate to find the node.y
- y-coordinate to find the node.
public void constructAnimatingBSTTreeHead()
public boolean isTreeRemove()
Animation
.
Animation
.public Animation getTreeAnimator()
Animation
in the list of Animations for the Head and null if no
Animations are present.
getTreeAnimator
in interface AnimatingTreeHead<P extends NodeProperties>
Animation
in the Animation list.public boolean isTreeAnimating()
isTreeAnimating
in interface AnimatingTreeHead<P extends NodeProperties>
public boolean isJumpStep()
isJumpStep
in interface AnimatingTreeHead<P extends NodeProperties>
public boolean isStepPause()
isStepPause
in interface AnimatingTreeHead<P extends NodeProperties>
public int getTreeAnimationStepSize()
Animation
s of the tree.
getTreeAnimationStepSize
in interface AnimatingTreeHead<P extends NodeProperties>
public java.lang.String getTreeStatus()
Animation
.
getTreeStatus
in interface AnimatingTreeHead<P extends NodeProperties>
Animation
status.public void saveTreeProperties()
public void popTreeProperties()
public void clearAnimators()
Animation
s from the list of Animations for the Head.
public void addTreeAnimator(Animation a)
Animation
to the list of Animations for the Head. The method does
not add the tree as a listener to the Animation
. That must be accomplished by
the client.
addTreeAnimator
in interface AnimatingTreeHead<P extends NodeProperties>
a
- Animation
added to the Animation list.public void removeTreeAnimation()
Animation.FINISH
so that all listeners of the Animations will
receive the AnimationEvent.
removeTreeAnimation
in interface AnimatingTreeHead<P extends NodeProperties>
public void setJumpStep(boolean b)
AnimateTree
call.
setJumpStep
in interface AnimatingTreeHead<P extends NodeProperties>
b
- sets the jumpStep to the value b.public void setStepPause(boolean b)
setStepPause
in interface AnimatingTreeHead<P extends NodeProperties>
b
- sets the stepPause to the value b.public void setTreeAnimationsStepSize(int t)
Animation
s of the tree. The integer value
is passed to every Animation's setStepTime
method.
setTreeAnimationsStepSize
in interface AnimatingTreeHead<P extends NodeProperties>
t
- integer step size setting.public void setTreeStatus(java.lang.String s)
Animation
class.
setTreeStatus
in interface AnimatingTreeHead<P extends NodeProperties>
s
- String status to set the Tree's Status.public void balanceAnimatingType(GrowingTreeNode<P> node)
balanceTREE
if no waiting action appears.
node
- BSTTree that is balanced from.public java.util.LinkedList<GrowingTreeNode<P>> traverseAnimatingType(int traverseType)
traverseType
- int defining the given traversal type.public void changeDisplayAnimatingType()
BSTTree
.
public Animation makeInsertAnimation(GrowingTreeNode<P> insertNode)
insertNode
- BSTTree node that the insert Animation is built for.
public Animation makeSearchAnimation(KeyType keySearch)
keySearch
- the comparable object which is search for within the tree.public Animation makeSelectionAnimation(GrowingTreeNode<P> node, int keySelect)
keySelect
- the int which is selected for within the tree.public Animation makeSwapNodesAnimation(GrowingTreeNode<P> node, int keySelect)
public Animation makeFreezeAnimation(double lengthMult)
public Animation makeRotationAnimation(GrowingTreeNode<P> node)
node
- BSTTree node that the rotation Animation is built from.
public Animation makeDeletionAnimation(GrowingTreeNode<P> node)
node
- BSTTree node that the deletion Animation is built from.
public Animation makePartitionAnimation(GrowingTreeNode<P> node, int keySelect)
node
- BSTTree node that the deletion Animation is built from.keySelect
- finds the keySelectth node and rotates it to the top.
public Animation makeBalanceAnimation(GrowingTreeNode<P> node)
node
- BSTTree node that the balance Animation is built from.
public Animation makeRotationDoubleAnimation(GrowingTreeNode<P> node)
node
- BSTTree node that the doubleRotation Animation is built from.
public Animation makeTraverseAnimation(java.util.LinkedList<GrowingTreeNode<P>> nodeList)
nodeList
- the LinkedList containing the nodes that are the path of the traversal.public Animation makeChangeDisplayAnimation()
public void AnimateTree(java.awt.Graphics2D g2)
drawAnimation
method is called. Within this method, checks for removing a Animation are made, as are checks
for Waiting Actions.
AnimateTree
in interface AnimatingTreeHead<P extends NodeProperties>
g2
- Graphics2D to which the Animation
s are drawn.public void play()
AnimatingBSTTree
to play.
play
in interface AnimatingTreeHead<P extends NodeProperties>
public void stop()
AnimatingBSTTree
to stop.
stop
in interface AnimatingTreeHead<P extends NodeProperties>
public void rewind()
AnimatingBSTTree
to rewind.
rewind
in interface AnimatingTreeHead<P extends NodeProperties>
public void pause()
AnimatingBSTTree
to pause.
pause
in interface AnimatingTreeHead<P extends NodeProperties>
public void animationEventPerformed(AnimationEvent e)
AnimationListener
which requires the following method.
The only status of animation it listens for is Animation.FINISH
, to remove
the animation from the animators list and Animation.STEP
, to possible pause
the animation if stepPause is true.
animationEventPerformed
in interface AnimationListener
animationEventPerformed
in class GrowingTreeNode<P extends NodeProperties>
e
- AnimationEvent that represents the information of the Animation.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |