File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
yoonexample/src/main/java/priorityqueue Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments