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 |
---|---|
void |
changed()
Notifies the queue that the first element has changed (optional operation).
|
void |
clear()
Removes all elements from this queue.
|
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.
|
boolean |
isEmpty()
Checks whether the queue is empty.
|
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()
NoSuchElementException
- if the queue is empty.boolean isEmpty()
int size()
void clear()
K first()
NoSuchElementException
- if the queue is empty.K last()
NoSuchElementException
- if the queue is empty.void changed()
Comparator<? super K> comparator()
null
if it uses its elements' natural ordering.null
if it uses its elements' natural ordering.