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

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

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

Binary heap implementation of a priority queue, in which items of the same priority are removed in order of insertion.

Author:
Peter Williams
See Also:
Comparable, BinaryHeap

Constructor Summary
StrictBinaryHeap()
          Constructs the binary heap.
 
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 item 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

StrictBinaryHeap

public StrictBinaryHeap()
Constructs the binary heap.

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 item from the heap.

If several items are currently of highest priority, returns them in order of insertion.

Specified by:
remove in interface PriorityQueue<E extends java.lang.Comparable<? super E>>
Returns:
the first item of highest priority that was inserted into the heap.
Throws:
NoSuchElementException - if the heap is empty.