Java中堆是采用优先级队列来实现的,如下:
Queue<Integer> minheap =new PriorityQueue<Integer>();//默认为创建最小堆
Queue<Integer> maxheap =new PriorityQueue<Integer>((n1, n2) -> n2-n1);//创建最大堆
Java中堆是采用优先级队列来实现的,如下:
Queue<Integer> minheap =new PriorityQueue<Integer>();//默认为创建最小堆
Queue<Integer> maxheap =new PriorityQueue<Integer>((n1, n2) -> n2-n1);//创建最大堆