public class HeapPriorityQueue implements PriorityQueue {
HeapTree T;
Comparator comp;
public HeapPriorityQueue(Comparator c) {
if ((comp = c) == null)
throw new IllegalArgumentException("Null comparator passed");
T = new VectorHeapTree();
}
public int size() {
return (T.size() - 1) / 2;
}
public boolean isEmpty() {
return T.size() == 1; }
public Object minElement() throws PriorityQueueEmptyException {
if (isEmpty())
throw new PriorityQueueEmptyException("Empty Priority Queue");
return element(T.root());
}
public Object minKey() throws PriorityQueueEmptyException {
if (isEmpty())
throw new PriorityQueueEmptyException("Empty Priority Queue");
return key(T.root());
}