K - key typeV - value typepublic final class MinHeap<K,V>
extends java.lang.Object
| Constructor and Description |
|---|
MinHeap(int cap,
java.util.Comparator<K> cmp)
Constructs a heap with the given initial capacity and order.
|
| Modifier and Type | Method and Description |
|---|---|
void |
insert(K key,
V value)
Inserts the given key/value pair into the heap.
|
boolean |
isEmpty()
Checks if this heap is empty.
|
V |
minValue()
returns the value of the smallest key from this heap.
|
V |
removeMin()
Removes the minimum from this heap.
|
int |
size()
Size of this heap.
|
java.lang.String |
toString() |
void |
verify()
Verifies the inner structure of the heap.
|
public MinHeap(int cap,
java.util.Comparator<K> cmp)
cap - initial capacitycmp - comparatorpublic void insert(K key, V value)
key - keyvalue - valuepublic V removeMin()
public V minValue()
public int size()
public boolean isEmpty()
true if heap is empty, false otherwisepublic void verify()
java.lang.IllegalStateException - if the invariants don't holdpublic java.lang.String toString()
toString in class java.lang.Object