u6
Class ArrayHeap

java.lang.Object
  |
  +--u6.Heap
        |
        +--u6.ArrayHeap

public class ArrayHeap
extends Heap

Array based implementation of Heap Data Structure. The nodes of binary tree of the heap are stored in a lenear structure.


Fields inherited from class u6.Heap
cmp, height, size
 
Constructor Summary
ArrayHeap(java.util.Comparator cmp)
          Constructs an empty heap with the specified comparator
ArrayHeap(java.util.Comparator comparator, Item[] aitem)
          Constructs a heap from the elements of 'aitem' using the bottom-up method.
 
Method Summary
 void add(Item entry)
          Adds the given item in the heap and updates the size and the height values.
 void bottomUp(int i)
          Constructs a heap with root the element with index 'i', using the bottom-up method.
 Item extractItem()
          Extracts the root of the Heap and updates the size and the height values.
 java.lang.Object readMinElement()
          Reads the element value of the item, stored in the root of the heap without removing the root.
 java.lang.Object readMinKey()
          Reads the key, stored in the root of the heap, without extracting the root.
 java.lang.Object[] toArray(java.lang.Object[] a)
           
 
Methods inherited from class u6.Heap
add, computeHeight, getHeight, isEmpty, size
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayHeap

public ArrayHeap(java.util.Comparator cmp)
Constructs an empty heap with the specified comparator

ArrayHeap

public ArrayHeap(java.util.Comparator comparator,
                 Item[] aitem)
Constructs a heap from the elements of 'aitem' using the bottom-up method.
Method Detail

bottomUp

public void bottomUp(int i)
Constructs a heap with root the element with index 'i', using the bottom-up method.

add

public void add(Item entry)
Adds the given item in the heap and updates the size and the height values.
Overrides:
add in class Heap

extractItem

public Item extractItem()
Extracts the root of the Heap and updates the size and the height values.
Overrides:
extractItem in class Heap

readMinKey

public java.lang.Object readMinKey()
Reads the key, stored in the root of the heap, without extracting the root.
Overrides:
readMinKey in class Heap

readMinElement

public java.lang.Object readMinElement()
Reads the element value of the item, stored in the root of the heap without removing the root.
Overrides:
readMinElement in class Heap

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)