|
@@ -3,18 +3,29 @@ package org.insa.algo.utils;
|
3
|
3
|
/**
|
4
|
4
|
* Interface representing a basic priority queue.
|
5
|
5
|
*
|
6
|
|
- * @see https://en.wikipedia.org/wiki/Priority_queue
|
|
6
|
+ * Implementation should enforce the required complexity of each method.
|
|
7
|
+ *
|
7
|
8
|
*/
|
8
|
9
|
public interface PriorityQueue<E extends Comparable<E>> {
|
9
|
10
|
|
10
|
11
|
/**
|
11
|
12
|
* Check if the priority queue is empty.
|
12
|
13
|
*
|
|
14
|
+ * <p>
|
|
15
|
+ * <b>Complexity:</b> <i>O(1)</i>
|
|
16
|
+ * </p>
|
|
17
|
+ *
|
13
|
18
|
* @return true if the queue is empty, false otherwise.
|
14
|
19
|
*/
|
15
|
20
|
public boolean isEmpty();
|
16
|
21
|
|
17
|
22
|
/**
|
|
23
|
+ * Get the number of elements in this queue.
|
|
24
|
+ *
|
|
25
|
+ * <p>
|
|
26
|
+ * <b>Complexity:</b> <i>O(1)</i>
|
|
27
|
+ * </p>
|
|
28
|
+ *
|
18
|
29
|
* @return Current size (number of elements) of this queue.
|
19
|
30
|
*/
|
20
|
31
|
public int size();
|
|
@@ -22,6 +33,10 @@ public interface PriorityQueue<E extends Comparable<E>> {
|
22
|
33
|
/**
|
23
|
34
|
* Insert the given element into the queue.
|
24
|
35
|
*
|
|
36
|
+ * <p>
|
|
37
|
+ * <b>Complexity:</b> <i>O(log n)</i>
|
|
38
|
+ * </p>
|
|
39
|
+ *
|
25
|
40
|
* @param x Item to insert.
|
26
|
41
|
*/
|
27
|
42
|
public void insert(E x);
|
|
@@ -29,6 +44,10 @@ public interface PriorityQueue<E extends Comparable<E>> {
|
29
|
44
|
/**
|
30
|
45
|
* Remove the given element from the priority queue.
|
31
|
46
|
*
|
|
47
|
+ * <p>
|
|
48
|
+ * <b>Complexity:</b> <i>O(log n)</i>
|
|
49
|
+ * </p>
|
|
50
|
+ *
|
32
|
51
|
* @param x Item to remove.
|
33
|
52
|
*/
|
34
|
53
|
public void remove(E x) throws ElementNotFoundException;
|
|
@@ -36,6 +55,10 @@ public interface PriorityQueue<E extends Comparable<E>> {
|
36
|
55
|
/**
|
37
|
56
|
* Retrieve (but not remove) the smallest item in the queue.
|
38
|
57
|
*
|
|
58
|
+ * <p>
|
|
59
|
+ * <b>Complexity:</b> <i>O(1)</i>
|
|
60
|
+ * </p>
|
|
61
|
+ *
|
39
|
62
|
* @return The smallest item in the queue.
|
40
|
63
|
*
|
41
|
64
|
* @throws EmptyPriorityQueueException if this queue is empty.
|
|
@@ -45,6 +68,10 @@ public interface PriorityQueue<E extends Comparable<E>> {
|
45
|
68
|
/**
|
46
|
69
|
* Remove and return the smallest item from the priority queue.
|
47
|
70
|
*
|
|
71
|
+ * <p>
|
|
72
|
+ * <b>Complexity:</b> <i>O(log n)</i>
|
|
73
|
+ * </p>
|
|
74
|
+ *
|
48
|
75
|
* @return The smallest item in the queue.
|
49
|
76
|
*
|
50
|
77
|
* @throws EmptyPriorityQueueException if this queue is empty.
|