Home > Back-end >  Java PriorityQueue questions
Java PriorityQueue questions

Time:10-01

Question:
1. The default little heap, output the minimum value at a time, why should the Java proposed on the basis of the existing Queue priority Queue, just can output the smallest or according to the value of the comparator output corresponding? These functions before the collection can not do?
2. The Pair of storage, custom class, when the Map is the need to define a constructor, and the Queue, List what's the difference? His advantage in where?

CodePudding user response:

Quequ attribute is first in first out, PriorityQueue are based on the further extension of function, can be made to dequeue elements to change the original order, give you an example explains: queue in the bank, if only queueu structure, everybody is in accordance with the order of the services to be first, then the problem is coming, if there is a VIP customers to the bank, he must wait until the last, so Banks will lose a big customer, if use PriorityQueue, can join priority, such as the VIP first, then the older, the last is general customer first come first service,

2. No type has its own features, know more read document

CodePudding user response:

Upstairs, Java priority Queue is a small pile of, if I would have to reverse the output I will need to add the comparator in the priority Queue, add the comparator with me directly in the Queue, the end result is not the same ~
  • Related