Class Heap

java.lang.Object
  |
  +--Heap

public class Heap
extends java.lang.Object

An implementation of a heap. Elements stored in the heap must implement the Comparable interface.


Constructor Summary
Heap()
          Construct a heap with initial capacity 10 and capacity increment 0
Heap(int c)
          Construct a heap with initial capacity c and capacity increment 0
Heap(int c, int ci)
          Construct a heap with initial capacity c and capacity increment ci
 
Method Summary
 int capacity()
          Return the capacity of the heap
 void insert(java.lang.Comparable value)
          Insert an element into the heap
 java.lang.Comparable remove()
          Remove top element from the heap
 int size()
          Return the size of the heap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Heap

public Heap()
Construct a heap with initial capacity 10 and capacity increment 0

Since:
1.0

Heap

public Heap(int c)
Construct a heap with initial capacity c and capacity increment 0

Parameters:
c - initial capacity for heap
Throws:
java.lang.IllegalArgumentException - c is negative
Since:
1.0

Heap

public Heap(int c,
            int ci)
Construct a heap with initial capacity c and capacity increment ci

Parameters:
c - initial capacity for heap
ci - capacity increment for heap
Throws:
java.lang.IllegalArgumentException - c or ci is negative
Since:
1.0
Method Detail

size

public int size()
Return the size of the heap

Returns:
the number of elements contained in the heap
Since:
1.0

capacity

public int capacity()
Return the capacity of the heap

Returns:
the size of the internal array used to store the heap
Since:
1.0

insert

public void insert(java.lang.Comparable value)
Insert an element into the heap

Parameters:
value - object to insert
Throws:
java.lang.IllegalArgumentException - value is null
Since:
1.0

remove

public java.lang.Comparable remove()
                            throws EmptyHeapException
Remove top element from the heap

Returns:
the element with the greatest value from the heap
Throws:
EmptyHeapException - heap is empty
Since:
1.0