Priority queue in .Net [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations. Closed 5 years ago. Improve this question I am looking for a .NET … Read more

How do I use a PriorityQueue?

How do I get a PriorityQueue to sort on what I want it to sort on? Also, is there a difference between the offer and add methods? Use the constructor overload which takes a Comparator<? super E> comparator and pass in a comparator which compares in the appropriate way for your sort order. If you give an example of how you want to … Read more

Change priorityQueue to max priorityqueue

How about like this: PriorityQueue<Integer> queue = new PriorityQueue<>(10, Collections.reverseOrder()); queue.offer(1); queue.offer(2); queue.offer(3); //… Integer val = null; while( (val = queue.poll()) != null) { System.out.println(val); } The Collections.reverseOrder() provides a Comparator that would sort the elements in the PriorityQueue in a the oposite order to their natural order in this case.