public interface PriorityQueue<K>
A priority queue provides a way to enqueue elements, and to dequeue them in some specified order. Elements that are smaller in the specified order are dequeued first. It is also possible to get the first element, that is, the element that would be dequeued next.
Additionally, the queue may provide a method to peek at element that would be dequeued last.
The relative order of the elements enqueued should not change during queue operations. Nonetheless, some implementations may give the caller a way to notify the queue that the first element has changed its relative position in the order.
Modifier and Type | Method and Description |
---|---|
default void |
changed()
Notifies the queue that the first element has changed (optional operation).
|
void |
clear()
Removes all elements from this queue.
|
java.util.Comparator<? super K> |
comparator()
Returns the comparator associated with this queue, or
null if it uses its elements' natural ordering. |
K |
dequeue()
Dequeues the first element from the queue.
|
void |
enqueue(K x)
Enqueues a new element.
|
K |
first()
Returns the first element of the queue.
|
default boolean |
isEmpty()
Checks whether this queue is empty.
|
default K |
last()
Returns the last element of the queue, that is, the element the would be dequeued last (optional operation).
|
int |
size()
Returns the number of elements in this queue.
|
void enqueue(K x)
x
- the element to enqueue.K dequeue()
java.util.NoSuchElementException
- if the queue is empty.default boolean isEmpty()
This default implementation checks whether size()
is zero.
int size()
void clear()
K first()
java.util.NoSuchElementException
- if the queue is empty.default K last()
This default implementation just throws an UnsupportedOperationException
.
java.util.NoSuchElementException
- if the queue is empty.default void changed()
This default implementation just throws an UnsupportedOperationException
.
java.util.Comparator<? super K> comparator()
null
if it uses its elements' natural ordering.null
if it uses its elements' natural ordering.