K - This is the type of the Key being used by the BinarySearchTree to position TreeItems in the treeV - This is the type of the Value associated with the Keypublic class TreeIterator<K extends java.lang.Comparable<? super K>,V> extends java.lang.Object implements java.util.Iterator<TreeItem<K,V>>
| Modifier and Type | Field and Description |
|---|---|
private BinarySearchTree<K,V> |
binarySearchTree |
private TreeNode<K,V> |
currentNode |
private java.util.Vector<TreeNode<K,V>> |
treeNodes |
| Constructor and Description |
|---|
TreeIterator(BinarySearchTree<K,V> binarySearchTree)
This is the constructor for the
TreeIterator. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
hasNext()
This method is used to verify that the
TreeIterator has more elements to return. |
private void |
inorder(TreeNode<K,V> treeNode) |
TreeItem<K,V> |
next()
This method is used to retrieve the next element from the
TreeIterator. |
private void |
postorder(TreeNode<K,V> treeNode) |
private void |
preorder(TreeNode<K,V> treeNode) |
void |
setInorder()
This method sets the order of retrieval from the
TreeIterator to be Inorder. |
void |
setPostorder()
This method sets the order of retrieval from the
TreeIterator to be Postorder. |
void |
setPreorder()
This method sets the order of retrieval from the
TreeIterator to be Preorder. |
int |
size()
This method is used to obtain the number of elements available in the iterator.
|
private BinarySearchTree<K extends java.lang.Comparable<? super K>,V> binarySearchTree
public TreeIterator(BinarySearchTree<K,V> binarySearchTree)
TreeIterator.binarySearchTree - The BinaryTreeBasis that this iterator will operate on.public int size()
TreeNode's available in the iterator.public boolean hasNext()
TreeIterator has more elements to return.public TreeItem<K,V> next() throws java.util.NoSuchElementException
TreeIterator.public void setPreorder()
TreeIterator to be Preorder.
This method will call the private method preorder() in order to populate the queue.public void setInorder()
TreeIterator to be Inorder.
This method will call the private method inorder() in order to populate the queue.public void setPostorder()
TreeIterator to be Postorder.
This method will call the private method postorder() in order to populate the queue.