All Packages Class Hierarchy This Package Previous Next Index
Class tw.edu.ncnu.im.cnclab.DataStru.BinaryHeap
java.lang.Object
|
+----tw.edu.ncnu.im.cnclab.DataStru.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.
- Author:
- Origional from Mark Allen Weiss , modified by Ding-Yi Chen on Mar 10, 1999.
-
BinaryHeap()
- Construct the binary heap.
-
BinaryHeap(Comparable11)
- Construct the binary heap.
-
BinaryHeap(Comparable11, int)
- Construct the binary heap.
-
BinaryHeap(int)
- Construct the binary heap.
-
deleteMin()
- Remove the smallest item from the priority queue.
-
findMin()
- Find the smallest item in the priority queue.
-
insert(Comparable11)
- Insert into the priority queue, maintaining heap order.
-
isEmpty()
- Test if the priority queue is logically empty.
-
makeEmpty()
- Make the priority queue logically empty.
-
toss(Comparable11)
- Insert into the priority queue, without maintaining
heap order.
-
validate()
- Validate the Heap
BinaryHeap
public BinaryHeap()
- Construct the binary heap.
BinaryHeap
public BinaryHeap(int size)
- Construct the binary heap.
- Parameters:
- size - the maximum size of the heap.
BinaryHeap
public BinaryHeap(Comparable11 negInf)
- Construct the binary heap.
- Parameters:
- negInf - a value smaller than or equal to all others.
BinaryHeap
public BinaryHeap(Comparable11 negInf,
int size)
- Construct the binary heap.
- Parameters:
- negInf - a value smaller than or equal to all others.
- size - the maximum size of the heap.
insert
public void insert(Comparable11 x)
- Insert into the priority queue, maintaining heap order.
Duplicates are allowed.
- Parameters:
- x - the item to insert.
toss
public void toss(Comparable11 x)
- Insert into the priority queue, without maintaining
heap order. Duplicates are allowed.
- Parameters:
- x - the item to insert.
findMin
public Comparable11 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 Comparable11 deleteMin() throws Underflow
- Remove the smallest item from the priority queue.
- Throws: Underflow
- if the priority queue is empty.
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.
validate
public void validate()
- Validate the Heap
All Packages Class Hierarchy This Package Previous Next Index