1. 선언
1 2 3 4 5 6 7 | import java.util.PriorityQueue; //import //int형 priorityQueue 선언 (최소힙) PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(); //int형 priorityQueue 선언 (최대힙) PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(Collections.reverseOrder()); | cs |
2. 값 추가
1 | priorityQueue.offer(3); | cs |
3. 값 삭제
1 | priorityQueue.poll(); // priorityQueue에 첫번째 값을 반환하고 제거 비어있다면 null | cs |
4. 값 출력
1 | priorityQueue.peek(); //Priority Queue에서 우선순위가 가장 높은 값 출력 | cs |
'Algorithm > PROGRAMMERS' 카테고리의 다른 글
[완전탐색] 완전탐색이란 (0) | 2020.11.24 |
---|---|
[힙(Hesp)] 더 맵게 JAVA (0) | 2020.11.10 |
[해시] HashMap 자주 쓰는 함수 정리 (0) | 2020.11.08 |
[해시] 완주하지 못한 선수 JAVA (0) | 2020.11.08 |