Class BinaryHeap

java.lang.Object
  extended byBinaryHeap
All Implemented Interfaces:
PriorityQueue

public class BinaryHeap
extends java.lang.Object
implements PriorityQueue

Binary heap implementation of a priority queue.


Constructor Summary
BinaryHeap()
          Constructs the binary heap.
 
Method Summary
 void add(java.lang.Comparable item)
          Adds and item to the heap.
 boolean isEmpty()
          Tests if the heap is empty.
 java.lang.Comparable remove()
          Removes an item of highest priority from the heap.
 int size()
          Returns the current size of the queue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinaryHeap

public BinaryHeap()
Constructs the binary heap.

Method Detail

isEmpty

public boolean isEmpty()
Tests if the heap is empty.

Specified by:
isEmpty in interface PriorityQueue
Returns:
true if empty, false otherwise.

size

public int size()
Returns the current size of the queue

Specified by:
size in interface PriorityQueue
Returns:
the current size of the queue

add

public void add(java.lang.Comparable item)
Adds and item to the heap.

Specified by:
add in interface PriorityQueue
Parameters:
item - the item to add.

remove

public java.lang.Comparable remove()
Removes an item of highest priority from the heap.

Specified by:
remove in interface PriorityQueue
Returns:
an item of highest priority.
Throws:
java.util.NoSuchElementException - if the heap is empty.