// 最小优先队列,直接 return o1.compareTo(o2); PriorityQueuequeue = new PriorityQueue (new Comparator (){ @Override public int compare(Integer o1, Integer o2){ return o1 < o2 ? -1 : 1; } }); // 最大优先队列,则反过来 return o2.compareTo(o1);

// 最小优先队列,直接 return o1.compareTo(o2); PriorityQueuequeue = new PriorityQueue (new Comparator (){ @Override public int compare(Integer o1, Integer o2){ return o1 < o2 ? -1 : 1; } }); // 最大优先队列,则反过来 return o2.compareTo(o1);