
앞쪽은 자연 순서에 따라 가장 적은 요소를 가지며 뒤쪽은 대기열에서 가장 큰 요소를 가리킵니다.
알파벳순 우선 순위 큐의 경우 ASCII 값이 고려되며 큐 요소는 ASCII 값에 따라 정렬됩니다.

삽입(enqueue) 및 삭제(dequeue) : O(log N)
PriorityQueue 요소는 자연스럽게 정렬됩니다. 순서를 변경하려면 비교자를 지정하고 PriorityQueue 객체를 생성하는 동안 사용해야 합니다. 그런 다음 PriorityQueue는 이 비교자를 사용하여 요소를 정렬합니다.
PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
//add element to the PriorityQueue
pq.add(8);
pq.add(6);
pq.add(4);
pq.add(2);
pq.add(12);
pq.add(10);
Integer val = null;
while( (val = pq.poll()) != null) {
System.out.print(val + " ");
2 4 6 8 10 12
//사용자지정비교자
PriorityQueue<Integer> pq = new PriorityQueue<Integer>(new Comparator<Integer>() {
public int compare(Integer lhs, Integer rhs) {
if (lhs < rhs) return +1;
if (lhs.equals(rhs)) return 0;
return -1;
}
});
//add element to the PriorityQueue
pq.add(8);
pq.add(6);
pq.add(4);
pq.add(2);
pq.add(12);
pq.add(10);
Integer val = null;
while( (val = pq.poll()) != null) {
System.out.print(val + " ");
12 10 8 6 4 2
Comparator.reverseOrder()를 사용하면 간단하게 내림차순으로 된다.
Queue<Integer> pQ = new PriorityQueue<>(Comparator.reverseOrder());//내림차순