Skip to content

Commit c5732f5

Browse files
committed
feat: 힙을 이용한 우선순위 큐의 구현 완료
1 parent 0b72fe1 commit c5732f5

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package priorityqueue;
2+
3+
import exception.EmptyQueueException;
4+
import heap.ArrayUsefulHeap;
5+
import heap.UsefulHeap;
6+
import java.util.Comparator;
7+
8+
public class HeapPriorityQueue<E> implements PriorityQueue<E> {
9+
10+
private final UsefulHeap<E> heap;
11+
12+
public HeapPriorityQueue(Comparator<E> comparator) {
13+
this.heap = new ArrayUsefulHeap<>(comparator);
14+
}
15+
16+
@Override
17+
public boolean isEmpty() {
18+
return this.heap.isEmpty();
19+
}
20+
21+
@Override
22+
public void enqueue(E data) {
23+
this.heap.insert(data);
24+
}
25+
26+
@Override
27+
public E dequeue() {
28+
if (isEmpty()) {
29+
throw new EmptyQueueException();
30+
}
31+
return this.heap.delete();
32+
}
33+
}

0 commit comments

Comments
 (0)