Package datastructures
Class SlowPQueue<E>
java.lang.Object
datastructures.SlowPQueue<E>
- All Implemented Interfaces:
PQueue<E>
A slow implementation of a priority queue where the
priorities are doubles. An asymptotically more efficient implementation
is possible!
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidEffect: Add e with priority p to the priority queue.voidchangePriority(E e, double priority) Effect: Change the priority of element e to p.Effect: Remove (and return) the element of the priority queue with highest priority.booleanisEmpty()Returns: true iff the priority queue is empty.peek()Returns: the element of the priority queue with highest priority, without changing the priority queue.intsize()Returns: the number of elements in the priority queue.
-
Constructor Details
-
SlowPQueue
public SlowPQueue()Creates: an empty queue
-
-
Method Details
-
size
public int size()Description copied from interface:PQueueReturns: the number of elements in the priority queue. -
isEmpty
public boolean isEmpty()Description copied from interface:PQueueReturns: true iff the priority queue is empty. -
peek
Description copied from interface:PQueueReturns: the element of the priority queue with highest priority, without changing the priority queue. Requires: the priority queue is not empty. -
add
Description copied from interface:PQueueEffect: Add e with priority p to the priority queue. Throw an illegalArgumentException if e is already in the queue.- Specified by:
addin interfacePQueue<E>- Throws:
IllegalArgumentException
-
extractMin
Description copied from interface:PQueueEffect: Remove (and return) the element of the priority queue with highest priority. Requires: the priority queue is not empty.- Specified by:
extractMinin interfacePQueue<E>
-
changePriority
Description copied from interface:PQueueEffect: Change the priority of element e to p. Requires: e is in the priority queue.- Specified by:
changePriorityin interfacePQueue<E>
-