DataStructures
Class BinaryHeap<E extends java.lang.Comparable<? super E>>

java.lang.Object
  extended by DataStructures.BinaryHeap<E>
Type Parameters:
E - the type of elements held in this heap
All Implemented Interfaces:
PriorityQueue<E>

public class BinaryHeap<E extends java.lang.Comparable<? super E>>
extends java.lang.Object
implements PriorityQueue<E>

Binary heap implementation of a priority queue.

Author:
Peter Williams
See Also:
Comparable, StrictBinaryHeap

Constructor Summary
BinaryHeap()
          Constructs an empty binary heap suitable for holding elements of type E.
 
Method Summary
 void add(E item)
          Adds an item to the heap.
 boolean isEmpty()
          Tests if the heap is empty.
 E 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
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinaryHeap

public BinaryHeap()
Constructs an empty binary heap suitable for holding elements of type E.

Method Detail

isEmpty

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

Specified by:
isEmpty in interface PriorityQueue<E extends java.lang.Comparable<? super E>>
Returns:
true if the queue is empty.

size

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

Specified by:
size in interface PriorityQueue<E extends java.lang.Comparable<? super E>>
Returns:
the current size of the queue

add

public void add(E item)
Adds an item to the heap.

Specified by:
add in interface PriorityQueue<E extends java.lang.Comparable<? super E>>
Parameters:
item - the item to be added.

remove

public E remove()
Removes an item of highest priority from the heap.

Specified by:
remove in interface PriorityQueue<E extends java.lang.Comparable<? super E>>
Returns:
an item of highest priority.