All Packages Class Hierarchy This Package Previous Next Index
Class DataStructures.BinaryHeap
java.lang.Object
|
+----DataStructures.BinaryHeap
- public class BinaryHeap
- extends Object
- implements PriorityQueue
Implements a binary heap.
Allows lazy insertion and provides a linear-time
heap construction method.
Note that all "matching" is based on the compares method.
-
BinaryHeap(Comparable)
- Construct the binary heap.
-
deleteMin()
- Remove the smallest item from the priority queue.
-
findMin()
- Find the smallest item in the priority queue.
-
fixHeap()
- Re-establish heap order property after a series of
toss operations.
-
insert(Comparable)
- Insert into the priority queue, maintaining heap order.
-
isEmpty()
- Test if the priority queue is logically empty.
-
main(String[])
-
-
makeEmpty()
- Make the priority queue logically empty.
-
toss(Comparable)
- Insert into the priority queue, without maintaining
heap order.
BinaryHeap
public BinaryHeap(Comparable negInf)
- Construct the binary heap.
- Parameters:
- negInf - a value smaller than or equal to all others.
insert
public void insert(Comparable x)
- Insert into the priority queue, maintaining heap order.
Duplicates are allowed.
- Parameters:
- x - the item to insert.
toss
public void toss(Comparable x)
- Insert into the priority queue, without maintaining
heap order. Duplicates are allowed.
- Parameters:
- x - the item to insert.
findMin
public Comparable findMin() throws Underflow
- Find the smallest item in the priority queue.
- Returns:
- the smallest item.
- Throws: Underflow
- if the priority queue is empty.
deleteMin
public Comparable deleteMin() throws Underflow
- Remove the smallest item from the priority queue.
- Throws: Underflow
- if the priority queue is empty.
fixHeap
public void fixHeap()
- Re-establish heap order property after a series of
toss operations. Runs in linear time.
isEmpty
public boolean isEmpty()
- Test if the priority queue is logically empty.
- Returns:
- true if empty, false otherwise.
makeEmpty
public void makeEmpty()
- Make the priority queue logically empty.
main
public static void main(String args[])
All Packages Class Hierarchy This Package Previous Next Index