public class ArrayHeap<E> extends AbstractSet<E> implements Heap<E>
Constructor and Description |
---|
ArrayHeap(Comparator<? super E> cmp)
Create an ArrayHeap.
|
ArrayHeap(Comparator<? super E> cmp,
int initCapacity) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(E o)
Adds an object to the heap.
|
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.
|
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.
|
String |
toString()
Prints the array entries in sorted comparator order.
|
void |
verify() |
equals, hashCode, removeAll
addAll, contains, containsAll, remove, retainAll, toArray, toArray
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addAll, contains, containsAll, remove, retainAll, spliterator, toArray, toArray
parallelStream, removeIf, stream
public ArrayHeap(Comparator<? super E> cmp)
cmp
- The objects added will be ordered using the Comparator
.public ArrayHeap(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 Iterator<E> iterator()
Heap
public void clear()
clear
in interface Collection<E>
clear
in interface Set<E>
clear
in class AbstractCollection<E>
public void dump()
public void verify()
public String toString()
toString
in class AbstractCollection<E>