public class MinHeap extends Object implements PriorityQueue
PriorityQueue.
Based on algorithm in Corman, Leiserson, Rivest, and Stein (Section 6.5).| Constructor and Description |
|---|
MinHeap()
Create a binary heap with minimum initial capacity.
|
MinHeap(int capacity)
Create a binary heap with initial capacity
capacity. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(QueueElement e)
Does the queue contain an element?
|
void |
decreaseKey(QueueElement e,
double priority)
Lower the priority of queue element
e to priorrity. |
QueueElement |
extractMin()
Remove the top element of the queue.
|
void |
insert(QueueElement e)
Insert element
e into the queue. |
QueueElement |
min()
Return the top element of the queue.
|
int |
size()
The current size of the queue.
|
public MinHeap(int capacity)
capacity.
The heap's capacity grows as needed to accomodate insertions.capacity - initial capacitypublic MinHeap()
public int size()
PriorityQueuesize in interface PriorityQueuepublic QueueElement min()
PriorityQueuemin in interface PriorityQueuepublic QueueElement extractMin()
PriorityQueueextractMin in interface PriorityQueuepublic void decreaseKey(QueueElement e, double priority)
PriorityQueuee to priorrity.
The element's position in the queue is adjusted as needed.
IllegalArgumentExceptions are thrown if the element is not in the queue or
if the new priority value is greater than the old value.decreaseKey in interface PriorityQueuee - the element that has been changedpriority - the new prioritypublic void insert(QueueElement e)
PriorityQueuee into the queue.insert in interface PriorityQueuee - the element to insertpublic boolean contains(QueueElement e)
PriorityQueuecontains in interface PriorityQueuee - the elementCopyright © 2019 JULIE Lab, Germany. All rights reserved.