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 TypeMethodDescriptionvoid
Effect: Add e with priority p to the priority queue.void
changePriority
(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.boolean
isEmpty()
Returns: true iff the priority queue is empty.peek()
Returns: the element of the priority queue with highest priority, without changing the priority queue.int
size()
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:PQueue
Returns: the number of elements in the priority queue. -
isEmpty
public boolean isEmpty()Description copied from interface:PQueue
Returns: true iff the priority queue is empty. -
peek
Description copied from interface:PQueue
Returns: 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:PQueue
Effect: Add e with priority p to the priority queue. Throw an illegalArgumentException if e is already in the queue.- Specified by:
add
in interfacePQueue<E>
- Throws:
IllegalArgumentException
-
extractMin
Description copied from interface:PQueue
Effect: Remove (and return) the element of the priority queue with highest priority. Requires: the priority queue is not empty.- Specified by:
extractMin
in interfacePQueue<E>
-
changePriority
Description copied from interface:PQueue
Effect: Change the priority of element e to p. Requires: e is in the priority queue.- Specified by:
changePriority
in interfacePQueue<E>
-