DataStructures
Class BinaryHeap

java.lang.Object
  |
  +--DataStructures.BinaryHeap

public class BinaryHeap
extends java.lang.Object

Implements a binary heap. Note that all "matching" is based on the compareTo method.


Constructor Summary
BinaryHeap()
          Construct the binary heap.
BinaryHeap(int capacity)
          Construct the binary heap.
 
Method Summary
 Comparable deleteMin()
          Remove the smallest item from the priority queue.
 Comparable findMin()
          Find the smallest item in the priority queue.
 void insert(Comparable x)
          Insert into the priority queue, maintaining heap order.
 boolean isEmpty()
          Test if the priority queue is logically empty.
 boolean isFull()
          Test if the priority queue is logically full.
static void main(java.lang.String[] args)
           
 void makeEmpty()
          Make the priority queue logically empty.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinaryHeap

public BinaryHeap()
Construct the binary heap.

BinaryHeap

public BinaryHeap(int capacity)
Construct the binary heap.
Parameters:
capacity - the capacity of the binary heap.
Method Detail

insert

public void insert(Comparable x)
            throws Overflow
Insert into the priority queue, maintaining heap order. Duplicates are allowed.
Parameters:
x - the item to insert.
Throws:
Overflow - if container is full.

findMin

public Comparable findMin()
Find the smallest item in the priority queue.
Returns:
the smallest item, or null, if empty.

deleteMin

public Comparable deleteMin()
Remove the smallest item from the priority queue.
Returns:
the smallest item, or null, if empty.

isEmpty

public boolean isEmpty()
Test if the priority queue is logically empty.
Returns:
true if empty, false otherwise.

isFull

public boolean isFull()
Test if the priority queue is logically full.
Returns:
true if full, false otherwise.

makeEmpty

public void makeEmpty()
Make the priority queue logically empty.

main

public static void main(java.lang.String[] args)