// add all items to copy of heap // takes linear time since already in heap order so no keys move public HeapIterator() { while (!max.isEmpty()) { copy.insert(max.delMax()); } while (!min.isEmpty()) { copy.insert(min.delMin()); } }
public Integer next() { if (!hasNext()) { throw new NoSuchElementException(); } return copy.deleteMedian(); }
public boolean hasNext() { return !copy.isEmpty(); }