public class NonEmptyTree<K extends java.lang.Comparable<K>,V> extends java.lang.Object implements Tree<K,V>
| Constructor and Description |
|---|
NonEmptyTree(K key,
V value,
Tree<K,V> left,
Tree<K,V> right)
Only constructor we need.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addKeysToCollection(java.util.Collection<K> c)
Add all keys bound in this tree to the collection c.
|
Tree<K,V> |
delete(K key)
Delete any binding the key has in this tree.
|
int |
height()
Returns the height (maximum level) in the tree.
|
void |
inorderTraversal(TraversalTask<K,V> p)
Performs the specified task on the tree using an inorder traversal.
|
NonEmptyTree<K,V> |
insert(K key,
V value)
Insert/update the Tree with a new key:value pair.
|
K |
max()
Return the maximum key in the subtree
|
K |
min()
Return the minimum key in the subtree
|
void |
rightRootLeftTraversal(TraversalTask<K,V> p)
Performs the specified task on the tree using a right tree, root, left tree
traversal.
|
V |
search(K key)
Find the value that this key is bound to in this tree.
|
int |
size()
Return number of keys that are bound in this tree.
|
Tree<K,V> |
subTree(K fromKey,
K toKey)
Returns a Tree containing all entries between fromKey and toKey, inclusive.
|
public V search(K key)
Treepublic NonEmptyTree<K,V> insert(K key, V value)
Treepublic Tree<K,V> delete(K key)
Treepublic int size()
Treepublic void addKeysToCollection(java.util.Collection<K> c)
TreeaddKeysToCollection in interface Tree<K extends java.lang.Comparable<K>,V>public Tree<K,V> subTree(K fromKey, K toKey)
Treepublic int height()
Treepublic void inorderTraversal(TraversalTask<K,V> p)
TreeinorderTraversal in interface Tree<K extends java.lang.Comparable<K>,V>p - object defining taskpublic void rightRootLeftTraversal(TraversalTask<K,V> p)
TreerightRootLeftTraversal in interface Tree<K extends java.lang.Comparable<K>,V>p - object defining task