Package minpq
Class HeapMinPQ<E>
- java.lang.Object
-
- minpq.HeapMinPQ<E>
-
-
Field Summary
Fields Modifier and Type Field Description private PriorityQueue<PriorityNode<E>>pqPriorityQueuestoringPriorityNodeobjects representing each element-priority pair.
-
Constructor Summary
Constructors Constructor Description HeapMinPQ()Constructs an empty instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(E element, double priority)Adds an element with the given priority value.voidchangePriority(E element, double priority)Updates the given elements' associated priority value.booleancontains(E element)Returns true if the given element is in this priority queue.EpeekMin()Returns the element with the minimum priority value.EremoveMin()Returns and removes the element with the minimum priority value.intsize()Returns the number of elements in this priority queue.
-
-
-
Field Detail
-
pq
private final PriorityQueue<PriorityNode<E>> pq
PriorityQueuestoringPriorityNodeobjects representing each element-priority pair.
-
-
Method Detail
-
add
public void add(E element, double priority)
Description copied from interface:MinPQAdds an element with the given priority value.
-
contains
public boolean contains(E element)
Description copied from interface:MinPQReturns true if the given element is in this priority queue.
-
peekMin
public E peekMin()
Description copied from interface:MinPQReturns the element with the minimum priority value.
-
removeMin
public E removeMin()
Description copied from interface:MinPQReturns and removes the element with the minimum priority value.
-
changePriority
public void changePriority(E element, double priority)
Description copied from interface:MinPQUpdates the given elements' associated priority value.- Specified by:
changePriorityin interfaceMinPQ<E>- Parameters:
element- the element whose associated priority value should be modified.priority- the updated priority value.
-
-