|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.util.AbstractCollection
common.BinaryHeap
public class BinaryHeap
A binary heap data structure, as described in Cormen, Leiserson & Rivest (1990) Chapter 7.
Implementation note: indices in the heap are 1-based.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface common.Heap |
|---|
Heap.Entry |
| Constructor Summary | |
|---|---|
BinaryHeap()
Creates a new, empty BinaryHeap. |
|
| Method Summary | |
|---|---|
Heap.Entry |
add(java.lang.Object o,
double cost)
Adds an entry to this heap for the given object and cost. |
void |
changeCost(Heap.Entry entry,
double newCost)
Changes the cost for the given entry. |
void |
clear()
Removes all elements from this heap. |
void |
decreaseCost(Heap.Entry entry,
double newCost)
Decreases the cost for the given entry. |
Heap.Entry |
extractMin()
Returns the minimum-cost entry in this heap and removes it from the heap. |
boolean |
isEmpty()
Returns true if this heap has no entries. |
java.util.Iterator |
iterator()
Returns an iterator over the Heap.Entry objects in this heap. |
static void |
main(java.lang.String[] args)
Test program. |
Heap.Entry |
peekMin()
Returns the minimum-cost entry in this heap, without modifying the heap. |
int |
size()
Returns the number of entries in this heap. |
| Methods inherited from class java.util.AbstractCollection |
|---|
add, addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Collection |
|---|
add, addAll, contains, containsAll, equals, hashCode, remove, removeAll, retainAll, toArray, toArray |
| Constructor Detail |
|---|
public BinaryHeap()
| Method Detail |
|---|
public int size()
size in interface java.util.Collectionsize in class java.util.AbstractCollectionpublic boolean isEmpty()
isEmpty in interface java.util.CollectionisEmpty in class java.util.AbstractCollectionpublic java.util.Iterator iterator()
iterator in interface java.lang.Iterableiterator in interface java.util.Collectioniterator in class java.util.AbstractCollectionpublic Heap.Entry peekMin()
peekMin in interface Heapjava.util.NoSuchElementException - if the heap is emptypublic Heap.Entry extractMin()
extractMin in interface Heapjava.util.NoSuchElementException - if the heap is empty
public Heap.Entry add(java.lang.Object o,
double cost)
add in interface Heappublic void clear()
clear in interface java.util.Collectionclear in class java.util.AbstractCollection
public void decreaseCost(Heap.Entry entry,
double newCost)
Warning: If the new cost is greater than the current one, this method will not produce an error message, but the heap may behave incorrectly.
decreaseCost in interface Heap
public void changeCost(Heap.Entry entry,
double newCost)
Heap
changeCost in interface Heappublic static void main(java.lang.String[] args)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||