dataStructures
Class MaxHeap

java.lang.Object
  |
  +--dataStructures.MaxHeap

public class MaxHeap
extends java.lang.Object
implements MaxPriorityQueue


Constructor Summary
MaxHeap()
          create a heap with initial capacity 10
MaxHeap(int initialCapacity)
          create a heap with the given initial capacity
 
Method Summary
 java.lang.Comparable getMax()
           
 void initialize(java.lang.Comparable[] theHeap, int theSize)
          initialize max heap to element array theHeap
 boolean isEmpty()
           
static void main(java.lang.String[] args)
          test program
 void put(java.lang.Comparable theElement)
          put theElement into the heap
 java.lang.Comparable removeMax()
          remove max element and return it
 int size()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MaxHeap

public MaxHeap(int initialCapacity)
create a heap with the given initial capacity
Throws:
java.lang.IllegalArgumentException - when initialCapacity < 1

MaxHeap

public MaxHeap()
create a heap with initial capacity 10
Method Detail

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface MaxPriorityQueue
Returns:
true iff the heap is empty

size

public int size()
Specified by:
size in interface MaxPriorityQueue
Returns:
number of elements in the heap

getMax

public java.lang.Comparable getMax()
Specified by:
getMax in interface MaxPriorityQueue
Returns:
maximum element

put

public void put(java.lang.Comparable theElement)
put theElement into the heap
Specified by:
put in interface MaxPriorityQueue

removeMax

public java.lang.Comparable removeMax()
remove max element and return it
Specified by:
removeMax in interface MaxPriorityQueue

initialize

public void initialize(java.lang.Comparable[] theHeap,
                       int theSize)
initialize max heap to element array theHeap

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)
test program