Package minpq
Interface MinPQ<E>
-
- Type Parameters:
E
- the type of elements in this priority queue.
- All Known Implementing Classes:
DoubleMapMinPQ
,HeapMinPQ
,OptimizedHeapMinPQ
,UnsortedArrayMinPQ
public interface MinPQ<E>
Priority queue where objects have extrinsic priority. WhereasPriorityQueue
relies onComparable
objects (or aComparator
), this interface requires priority values represented usingdouble
values. Elements must be unique, but priority values do not need to be unique.- See Also:
DoubleMapMinPQ
,UnsortedArrayMinPQ
,HeapMinPQ
,OptimizedHeapMinPQ
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
add(E element, double priority)
Adds an element with the given priority value.void
changePriority(E element, double priority)
Updates the given elements' associated priority value.boolean
contains(E element)
Returns true if the given element is in this priority queue.default boolean
isEmpty()
Returns true if this priority queue contains no elements.E
peekMin()
Returns the element with the minimum priority value.E
removeMin()
Returns and removes the element with the minimum priority value.int
size()
Returns the number of elements in this priority queue.
-
-
-
Method Detail
-
add
void add(E element, double priority)
Adds an element with the given priority value.- Parameters:
element
- the element to add.priority
- the priority value for the element.- Throws:
IllegalArgumentException
- if element is null or already present.
-
contains
boolean contains(E element)
Returns true if the given element is in this priority queue.- Parameters:
element
- element to be checked for containment.- Returns:
- true if the given element is in this priority queue.
-
peekMin
E peekMin()
Returns the element with the minimum priority value.- Returns:
- the element with the minimum priority value.
- Throws:
NoSuchElementException
- if this priority queue is empty.
-
removeMin
E removeMin()
Returns and removes the element with the minimum priority value.- Returns:
- the element with the minimum priority value.
- Throws:
NoSuchElementException
- if this priority queue is empty.
-
changePriority
void changePriority(E element, double priority)
Updates the given elements' associated priority value.- Parameters:
element
- the element whose associated priority value should be modified.priority
- the updated priority value.- Throws:
NoSuchElementException
- if the element is not present.
-
size
int size()
Returns the number of elements in this priority queue.- Returns:
- the number of elements in this priority queue.
-
isEmpty
default boolean isEmpty()
Returns true if this priority queue contains no elements.- Returns:
- true if this priority queue contains no elements.
-
-