Java : Priority Queue

前端 未结 3 1610
情深已故
情深已故 2021-01-18 05:41

I have a java program which goes like this

public class PriorityQueueExample {

public static void main(String[] args) {
    PriorityQueue

        
3条回答
  •  孤城傲影
    2021-01-18 06:16

    Insertion into a priority queue is not enough to sort a list of elements, since it doesn't store them in sorted order; it stores them in the partially sorted heap order. You have to remove the elements in a loop to sort them:

    while (pq.size() > 0)
        System.out.println(pq.remove());
    

提交回复
热议问题