Thursday, December 15, 2016

Is PriorityQueue sorted?

PriorityQueue is not sorted. It is guaranteed that only the first element is "sorted" (PriorityQueue is specified only to return lowest element every time head is requested). The whole queue could be sorted, but this is not guaranteed.

So PriorityQueue iterator returns elements in any order, not in sorted order. Assuming sorted order is a common bug.

No comments:

Post a Comment