Example #1
0
 // if iterStack is empty, we are at the end
 public boolean hasNext() {
   if (iterQueue.isEmpty()) {
     return false;
   } else {
     return true;
   }
 }
Example #2
0
    /*
     *	uses iterator to output what the next value is, T output
     */
    public T next() {
      if (!hasNext()) {
        throw new NoSuchElementException();
      }

      BSTNode current = iterQueue.dequeue();

      if (current.left != null) {
        iterQueue.enqueue(current.left);
      }
      if (current.right != null) {
        iterQueue.enqueue(current.right);
      }

      return current.element;
    }
Example #3
0
 // creates level order iterator
 public LevelIter() {
   // if the BST has nodes, push the root to iterator first
   if (!isEmpty()) {
     iterQueue.enqueue(root);
   }
 }