阅读本文章前请先阅读java实现数据结构08.01(堆详解代码之自定义最大堆)
基于最大堆自定义优先队列
/**
* @description: 优先队列,基于最大堆实现自定义优先队列
* @author: liangrui
* @create: 2019-12-18 12:15
**/
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();
}
}
来源:CSDN
作者:良睿
链接:https://blog.csdn.net/liangruilz/article/details/103598700