Wrong order in java.util.PriorityQueue and specific Comparator

后端 未结 1 1935
醉梦人生
醉梦人生 2021-01-29 06:10

i am very confused with this little example of java.util.PriorityQueue and my own Comparator:

In this code i get a wrong order in the queue. The result is: 5,8,7

相关标签:
1条回答
  • 2021-01-29 06:50

    A PriorityQueue doesn't store its elements in order. It gives them back to you in order.

    If you called poll() three times on the PriorityQueue, you'd get your elements back in the appropriate order.

    0 讨论(0)
提交回复
热议问题