jds.collection
Class Heap

java.lang.Object
  |
  +--jds.collection.Heap

public class Heap
extends java.lang.Object
implements FindMin, SortAlgorithm

Heap - priority queue implemented using the Heap data structure; for use with book Classic Data Structures in Java by Timothy A Budd, published by Addison-Wesley, 2001.

See Also:
Serialized Form

Constructor Summary
Heap(java.util.Comparator t)
          initialize a newly created heap
Heap(java.util.Comparator t, Indexed data)
          initialize a newly created heap
 
Method Summary
 void addElement(java.lang.Object val)
          add a new value to the collection
 java.util.Enumeration elements()
          Yields enumerator for collection
 java.lang.Object getFirst()
          yields the smallest element in collection
 boolean isEmpty()
          Determines whether the collection is empty
 void removeFirst()
          removes the smallest element in collection
 int size()
          Determines number of elements in collection
 void sort(Indexed data)
          rearrange collection into asending order
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Heap

public Heap(java.util.Comparator t)
initialize a newly created heap
Parameters:
t - comparator used to order values

Heap

public Heap(java.util.Comparator t,
            Indexed data)
initialize a newly created heap
Parameters:
t - comparator used to order values
data - initial data values
Method Detail

elements

public java.util.Enumeration elements()
Yields enumerator for collection
Returns:
an Enumeration that will yield the elements of the collection
See Also:
Enumeration

isEmpty

public boolean isEmpty()
Determines whether the collection is empty
Returns:
true if the collection is empty

size

public int size()
Determines number of elements in collection
Returns:
number of elements in collection as integer

addElement

public void addElement(java.lang.Object val)
add a new value to the collection
Specified by:
addElement in interface FindMin
Parameters:
value - element to be inserted into collection

getFirst

public java.lang.Object getFirst()
yields the smallest element in collection
Specified by:
getFirst in interface FindMin
Returns:
the first (smallest) value in collection

removeFirst

public void removeFirst()
removes the smallest element in collection
Specified by:
removeFirst in interface FindMin

sort

public void sort(Indexed data)
rearrange collection into asending order
Specified by:
sort in interface SortAlgorithm
Parameters:
data - the values to be ordered