|
|||||||||
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.Collection
size
in class java.util.AbstractCollection
public boolean isEmpty()
isEmpty
in interface java.util.Collection
isEmpty
in class java.util.AbstractCollection
public java.util.Iterator iterator()
iterator
in interface java.lang.Iterable
iterator
in interface java.util.Collection
iterator
in class java.util.AbstractCollection
public Heap.Entry peekMin()
peekMin
in interface Heap
java.util.NoSuchElementException
- if the heap is emptypublic Heap.Entry extractMin()
extractMin
in interface Heap
java.util.NoSuchElementException
- if the heap is emptypublic Heap.Entry add(java.lang.Object o, double cost)
add
in interface Heap
public void clear()
clear
in interface java.util.Collection
clear
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 Heap
public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |