S
S
synapse_people2016-01-29 10:42:37
Java
synapse_people, 2016-01-29 10:42:37

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

1 answer(s)
A
Alexander Dorofeev, 2016-01-29
@synapse_people

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 question

Ask a Question

731 491 924 answers to any question