/* * 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; }
// creates level order iterator public LevelIter() { // if the BST has nodes, push the root to iterator first if (!isEmpty()) { iterQueue.enqueue(root); } }