공부/알고리즘
우선순위 큐
확두뇌
2024. 1. 7. 16:27
//Queue<Integer> queue = new PriorityQueue<>(); //min heap
Queue<Integer> queue = new PriorityQueue<>(Collections.reverseOrder()); //max heap
queue.add(2);
queue.add(3);
queue.add(7);
queue.add(1);
int size = queue.size();
for(int i=0; i<size; i++) {
System.out.println("poll "+i+": "+queue.poll());
}
queue.peek(); //peek값 삭제 안하고 출력
queue.poll(); //삭제
//min heap : 1,2,3,7
//max heap : 7,3,2,1