|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface TreeHead<P extends NodeProperties>
The TreeHead interface extends the Tree interface. The TreeHead is used as the top null node of any given Tree. This implementation makes many necessary methods easier to perform with a null head node. The head node must implement all pertinent methods defined in the interface.
Generally, the TreeHead extends from the Tree in most cases and simply includes more defined methods.
The constructor generally constructs the Tree super construction first and then proceeds to the Head
defined methods. Consequently, the TreeHead is simply an extended Tree
with null information.
Field Summary | |
---|---|
static java.lang.String |
BALANCE_NODE
String representing the waiting action of balance . |
static java.lang.String |
CHANGE_DISPLAY
String representing the waiting action of changeDisplay . |
static java.lang.String |
FREEZE
String representing the waiting action of freeze |
static int |
INORDER_TRAVERSAL
Traverse type inorder. |
static java.lang.String |
INSERT_NODE
String representing the waiting action of insert . |
static int |
LEVELORDER_TRAVERSAL
Traverse type levelorder. |
static java.lang.String |
PARTITION_NODE
String representing the waiting action of partition . |
static int |
POSTORDER_TRAVERSAL
Traverse type postorder. |
static int |
PREORDER_TRAVERSAL
Traverse type preorder. |
static java.lang.String |
REMOVE_NODE
String representing the waiting action of remove . |
static java.lang.String |
ROTATE_TO_TOP_NODE
String representing the waiting action of rotateToTop . |
static java.lang.String |
ROTATE_UP
String representing the waiting action of rotateUp . |
static java.lang.String |
ROTATE_UP_DOUBLE
String representing the waiting action of rotateUpDouble . |
static java.lang.String |
SEARCH
String representing the waiting action of search . |
static java.lang.String |
SELECT
String representing the waiting action of select . |
static java.lang.String |
SPLAY_NODE
String representing the waiting action of splay . |
static java.lang.String |
SWAP
String representing the waiting action of swap. |
static java.lang.String |
TRAVERSE
String representing the waiting action of traverse . |
Method Summary | |
---|---|
void |
addTreeMessageListener(TreeMessageListener l)
Adds an TreeMessageListener from the tree, according to the TreeMessageListener interface and the TreeMessageEvent . |
void |
balance(Tree<P> node)
Balances the tree, from the node downward. |
void |
balanceTree()
Balances the entire tree. |
void |
clear()
Clears the tree completely, removing all references to all nodes and all values return to the default. |
void |
fixLevel()
Fixes the lowest level of the Tree . |
Tree<P> |
getChild()
Gets the child of the TreeHead. |
int |
getTreeLevel()
Gets the lowest level of the Tree. |
boolean |
insert(KeyType keyInsert,
java.lang.Object valueInsert)
Adds the comaparable object keyInsert to the tree using its natural ordering . |
boolean |
isTreeEmpty()
Returns true if the |
Tree<P> |
partition(Tree<P> node,
int keySelect)
Partitions from the given node the keySelect value. |
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 |
removeTreeMessageListener(TreeMessageListener l)
Removes an TreeMessageListener from the tree, according to the TreeMessageListener interface and the TreeMessageEvent . |
void |
resetTreeLevel()
Resets the lowest level of the Tree . |
Tree<P> |
search(KeyType keySearch)
Searches for the comaparable object in the Tree using its natural ordering . |
Tree<P> |
select(Tree<P> node,
int keySelect)
Selects the kth smallest item in the Tree using its natural ordering from the given node. |
void |
setChild(Tree<P> child)
Sets the child of the TreeHead. |
int |
size()
Returns the number of objects in the entire tree. |
void |
waitingAction(java.lang.String action,
ActionElementType<P> element)
Acts according to the String action passed. |
Methods inherited from interface edu.princeton.cs.algs4.growingtree.framework.Tree |
---|
getChildren, getKey, getLevel, getParentTree, getValue, isEmpty |
Field Detail |
---|
static final java.lang.String ROTATE_UP
rotateUp
. Requires an accompanying node.
static final java.lang.String ROTATE_TO_TOP_NODE
rotateToTop
. Requires an accompanying node.
static final java.lang.String ROTATE_UP_DOUBLE
rotateUpDouble
. Requires an accompanying node.
static final java.lang.String SPLAY_NODE
splay
. Requires an accompanying node.
static final java.lang.String REMOVE_NODE
remove
. Requires an accompanying node.
static final java.lang.String INSERT_NODE
insert
. Requires an accompanying node.
static final java.lang.String SEARCH
search
. Requires an accompanying node.
static final java.lang.String SELECT
select
. Requires an accompanying node.
static final java.lang.String SWAP
static final java.lang.String FREEZE
static final java.lang.String PARTITION_NODE
partition
. Requires an accompanying NodeAndKey
object (Inner class of BSTTreeHead).
static final java.lang.String BALANCE_NODE
balance
. Requires an accompanying NodeAndKey
object (Inner class of BSTTreeHead).
static final java.lang.String TRAVERSE
traverse
. Requires an accompanying Integer
object.
static final java.lang.String CHANGE_DISPLAY
changeDisplay
.
static final int PREORDER_TRAVERSAL
static final int INORDER_TRAVERSAL
static final int POSTORDER_TRAVERSAL
static final int LEVELORDER_TRAVERSAL
Method Detail |
---|
boolean isTreeEmpty()
TreeHead
is empty.void resetTreeLevel()
Tree
.
int getTreeLevel()
Tree
.void fixLevel()
Tree
.
void setChild(Tree<P> child)
child
- Tree
, beginning the Tree
nodes.Tree<P> getChild()
child
- Tree
, beginning the Tree
nodes.void addTreeMessageListener(TreeMessageListener l)
TreeMessageEvent
.
l
- the listener added recieves the TreeMessageEvents occuring.void removeTreeMessageListener(TreeMessageListener l)
TreeMessageEvent
.
l
- the listener removed from recieving the TreeMessageEvents occuring.boolean insert(KeyType keyInsert, java.lang.Object valueInsert) throws java.lang.ClassCastException, java.lang.NullPointerException
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.void remove(Tree<P> node) throws java.lang.NullPointerException
node
- the Tree
node to be removed from the tree.
java.lang.NullPointerException
- node is null
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.
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.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, null is
returned.
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.Tree<P> partition(Tree<P> node, int keySelect)
node
- Tree which the partition occurs at.keySelect
- integer key selecting the count item.
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.
node
- Tree which the partition occurs at.keySelect
- integer key selecting the count item.
void balanceTree()
void balance(Tree<P> node)
node
- the Tree node from which the balance occursint size()
size
in interface Tree<P extends NodeProperties>
void clear()
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.
action
- String action representing the next action for the TreeHead.elements
- elemetns to which the action could be occuring, depending on the type of action.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |