[JAVA] Priority Queue max Make it a queue
I forgot a little, so I'll make a note here.
Usually the Priority Queue is the minimum heap.
PriorityQueue pq= new PriorityQueue();
pq.poll (); // This gets the smallest element
To be able to get this in order from the maximum heap
PriorityQueue pq = new PriorityQueue<>(Collections.reverseOrder());
You can do it.
Later, if you want to use a specific field of the object
PriorityQueue pq = new PriorityQueue(Comparator.comparing(SumTree::getAge));
Or
PriorityQueue pq = new PriorityQueue(Comparator.comparing(SumTree::getAge).reversed());
You can do it.