Package minpq
Class UnsortedArrayMinPQ<E>
- java.lang.Object
-
- minpq.UnsortedArrayMinPQ<E>
-
-
Field Summary
Fields Modifier and Type Field Description private List<PriorityNode<E>>
elements
List
ofPriorityNode
objects representing the element-priority pairs in no specific order.
-
Constructor Summary
Constructors Constructor Description UnsortedArrayMinPQ()
Constructs an empty instance.
-
Method Summary
All Methods Instance Methods Concrete 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.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.
-
-
-
Field Detail
-
elements
private final List<PriorityNode<E>> elements
List
ofPriorityNode
objects representing the element-priority pairs in no specific order.
-
-
Method Detail
-
add
public void add(E element, double priority)
Description copied from interface:MinPQ
Adds an element with the given priority value.
-
contains
public boolean contains(E element)
Description copied from interface:MinPQ
Returns true if the given element is in this priority queue.
-
peekMin
public E peekMin()
Description copied from interface:MinPQ
Returns the element with the minimum priority value.
-
removeMin
public E removeMin()
Description copied from interface:MinPQ
Returns and removes the element with the minimum priority value.
-
changePriority
public void changePriority(E element, double priority)
Description copied from interface:MinPQ
Updates the given elements' associated priority value.- Specified by:
changePriority
in interfaceMinPQ<E>
- Parameters:
element
- the element whose associated priority value should be modified.priority
- the updated priority value.
-
-