Answer the question
In order to leave comments, you need to log in
How to take min and max element of PriorityQueue?
Actually there is a PriorityQueue, and a Comparator that sorts in ascending order (0,1,2,3,4...). How can you get the minimum element 0 from it, and then immediately get 4?
That is, you need to pull out 2 elements at once with the maximum and min. priority. Thank you.
Answer the question
In order to leave comments, you need to log in
The concept of accessing elements by index is not inherent in queues. In Java, too.
You can use a third party Guava library: (class MinMaxPriorityQueue )
You can also use LinkedList with a little bit of magic.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question