public class ArrayHeap<E> extends java.util.AbstractSet<E> implements Heap<E>
Constructor and Description |
---|
ArrayHeap(java.util.Comparator<? super E> cmp)
Create an ArrayHeap.
|
ArrayHeap(java.util.Comparator<? super E> cmp,
int initCapacity) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(E o)
Adds an object to the heap.
|
java.util.List<E> |
asList() |
void |
clear()
Clears the heap.
|
int |
decreaseKey(E o)
Changes the position of an element o in the heap based on a
change in the ordering of o.
|
void |
dump() |
E |
extractMin()
Finds the object with the minimum key, removes it from the heap,
and returns it.
|
boolean |
isEmpty()
Checks if the heap is empty.
|
java.util.Iterator<E> |
iterator()
Returns an iterator over its elements, in order.
|
E |
min()
Finds the object with the minimum key and returns it, without
modifying the heap.
|
int |
size()
Get the number of elements in the heap.
|
java.lang.String |
toString()
Prints the array entries in sorted comparator order.
|
void |
verify() |
addAll, contains, containsAll, remove, retainAll, toArray, toArray
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
public ArrayHeap(java.util.Comparator<? super E> cmp)
cmp
- The objects added will be ordered using the Comparator
.public ArrayHeap(java.util.Comparator<? super E> cmp, int initCapacity)
public E extractMin()
extractMin
in interface Heap<E>
public E min()
public boolean add(E o)
public int decreaseKey(E o)
decreaseKey
in interface Heap<E>
o
- An Object
valuepublic boolean isEmpty()
public int size()
public java.util.Iterator<E> iterator()
Heap
iterator
in interface Heap<E>
iterator
in interface java.lang.Iterable<E>
iterator
in interface java.util.Collection<E>
iterator
in interface java.util.Set<E>
iterator
in class java.util.AbstractCollection<E>
Iterator
valuepublic void clear()
public void dump()
public void verify()
public java.util.List<E> asList()
public java.lang.String toString()
toString
in class java.util.AbstractCollection<E>