优先级队列默认按照自然顺序(由小到大)排序,如何使优先队列按照从大到小的顺序排列呢?

具体实现如下
PriorityQueue<Integer> maxFirst = new PriorityQueue<Integer>(11, new Comparator<Integer>() {
public int compare(Integer o1, Integer o2) {
return o2 - o1;
}
});
优先级队列默认按照自然顺序(由小到大)排序,如何使优先队列按照从大到小的顺序排列呢?
具体实现如下
PriorityQueue<Integer> maxFirst = new PriorityQueue<Integer>(11, new Comparator<Integer>() {
public int compare(Integer o1, Integer o2) {
return o2 - o1;
}
});
本文标题:自定义比较顺序的优先级队列
本文链接:https://www.haomeiwen.com/subject/sgswrxtx.html
网友评论