Package org.insa.graphs.algorithm.utils
Interface PriorityQueue<E extends java.lang.Comparable<E>>
-
- All Known Implementing Classes:
BinaryHeap
,BinarySearchTree
public interface PriorityQueue<E extends java.lang.Comparable<E>>
Interface representing a basic priority queue. Implementation should enforce the required complexity of each method.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description E
deleteMin()
Remove and return the smallest item from the priority queue.E
findMin()
Retrieve (but not remove) the smallest item in the queue.void
insert(E x)
Insert the given element into the queue.boolean
isEmpty()
Check if the priority queue is empty.void
remove(E x)
Remove the given element from the priority queue.int
size()
Get the number of elements in this queue.
-
-
-
Method Detail
-
isEmpty
boolean isEmpty()
Check if the priority queue is empty.Complexity: O(1)
- Returns:
- true if the queue is empty, false otherwise.
-
size
int size()
Get the number of elements in this queue.Complexity: O(1)
- Returns:
- Current size (number of elements) of this queue.
-
insert
void insert(E x)
Insert the given element into the queue.Complexity: O(log n)
- Parameters:
x
- Item to insert.
-
remove
void remove(E x) throws ElementNotFoundException
Remove the given element from the priority queue.Complexity: O(log n)
- Parameters:
x
- Item to remove.- Throws:
ElementNotFoundException
-
findMin
E findMin() throws EmptyPriorityQueueException
Retrieve (but not remove) the smallest item in the queue.Complexity: O(1)
- Returns:
- The smallest item in the queue.
- Throws:
EmptyPriorityQueueException
- if this queue is empty.
-
deleteMin
E deleteMin() throws EmptyPriorityQueueException
Remove and return the smallest item from the priority queue.Complexity: O(log n)
- Returns:
- The smallest item in the queue.
- Throws:
EmptyPriorityQueueException
- if this queue is empty.
-
-