Package minpq
Class UnsortedArrayMinPQ<T>
- java.lang.Object
-
- minpq.UnsortedArrayMinPQ<T>
-
- Type Parameters:
T
- the type of elements in this priority queue.
- All Implemented Interfaces:
ExtrinsicMinPQ<T>
public class UnsortedArrayMinPQ<T> extends Object implements ExtrinsicMinPQ<T>
Unsorted array (orArrayList
) implementation of theExtrinsicMinPQ
interface.- See Also:
ExtrinsicMinPQ
-
-
Field Summary
Fields Modifier and Type Field Description private List<PriorityNode<T>>
items
List
ofPriorityNode
objects representing the item-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(T item, double priority)
Adds an item with the given priority value.void
changePriority(T item, double priority)
Updates the given items' associated priority value.boolean
contains(T item)
Returns true if the given item is in this priority queue.private int
indexOf(T item)
T
peekMin()
Returns the item with the minimum priority value.T
removeMin()
Returns and removes the item with the minimum priority value.int
size()
Returns the number of items in this priority queue.-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface minpq.ExtrinsicMinPQ
isEmpty
-
-
-
-
Field Detail
-
items
private final List<PriorityNode<T>> items
List
ofPriorityNode
objects representing the item-priority pairs in no specific order.
-
-
Method Detail
-
add
public void add(T item, double priority)
Description copied from interface:ExtrinsicMinPQ
Adds an item with the given priority value.- Specified by:
add
in interfaceExtrinsicMinPQ<T>
- Parameters:
item
- the element to add.priority
- the priority value for the item.
-
contains
public boolean contains(T item)
Description copied from interface:ExtrinsicMinPQ
Returns true if the given item is in this priority queue.- Specified by:
contains
in interfaceExtrinsicMinPQ<T>
- Parameters:
item
- element to be checked for containment.- Returns:
- true if the given item is in this priority queue.
-
peekMin
public T peekMin()
Description copied from interface:ExtrinsicMinPQ
Returns the item with the minimum priority value.- Specified by:
peekMin
in interfaceExtrinsicMinPQ<T>
- Returns:
- the item with the minimum priority value.
-
removeMin
public T removeMin()
Description copied from interface:ExtrinsicMinPQ
Returns and removes the item with the minimum priority value.- Specified by:
removeMin
in interfaceExtrinsicMinPQ<T>
- Returns:
- the item with the minimum priority value.
-
changePriority
public void changePriority(T item, double priority)
Description copied from interface:ExtrinsicMinPQ
Updates the given items' associated priority value.- Specified by:
changePriority
in interfaceExtrinsicMinPQ<T>
- Parameters:
item
- the element whose associated priority value should be modified.priority
- the updated priority value.
-
size
public int size()
Description copied from interface:ExtrinsicMinPQ
Returns the number of items in this priority queue.- Specified by:
size
in interfaceExtrinsicMinPQ<T>
- Returns:
- the number of elements in this priority queue.
-
indexOf
private int indexOf(T item)
-
-