基于堆的优先队列
public class PriorityQueue<E extends Comparable<E>> implements Queue<E> {
/**
* 底层基于最大堆
*/
private MaxHeap<E> maxHeap;
/**
* 无参构造函数
*/
public PriorityQueue() {
maxHeap = new MaxHeap<>();
}
@Override
public void enqueue(E e) {
maxHeap.add(e);
}
@Override
public E dequeue() {
return maxHeap.extractMax();
}
@Override
public E getFront() {
return maxHeap.findMax();
}
@Override
public int getSize() {
return maxHeap.getSize();
}
@Override
public boolean isEmpty() {
return maxHeap.isEmpty();
}
}