I have priority queue in Java of Integers:
PriorityQueue<Integer> pq= new PriorityQueue<Integer>();
When I call pq.poll() I get the minimum element.
Question: how to change the code to get the maximum element?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
How about like this:
The
Collections.reverseOrder()provides aComparatorthat would sort the elements in thePriorityQueuein a the oposite order to their natural order in this case.