com.mhhe.clrs2e
Class MinHeap

java.lang.Object
  |
  +--com.mhhe.clrs2e.Heap
        |
        +--com.mhhe.clrs2e.MinHeap
Direct Known Subclasses:
MinHeapPriorityQueue

public class MinHeap
extends Heap

Implements a binary min-heap, based on Chapter 6 of Introduction to Algorithms, Second edition.


Nested Class Summary
 
Nested classes inherited from class com.mhhe.clrs2e.Heap
Heap.Handle, Heap.Heapsort
 
Field Summary
 
Fields inherited from class com.mhhe.clrs2e.Heap
array, heapSize
 
Constructor Summary
(package private) MinHeap()
          Creates an empty min-heap.
(package private) MinHeap(java.lang.Comparable[] array)
          Makes a min-heap in place from the argument, and ensures that the min-heap property holds.
 
Method Summary
 void heapify(int i)
          Restores the min-heap property.
 
Methods inherited from class com.mhhe.clrs2e.Heap
buildHeap, exchange, head, isEmpty, left, makeSorter, parent, right
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MinHeap

MinHeap()
Creates an empty min-heap.


MinHeap

MinHeap(java.lang.Comparable[] array)
Makes a min-heap in place from the argument, and ensures that the min-heap property holds.

Parameters:
array - Array from which a min-heap is made.
Method Detail

heapify

public void heapify(int i)
Restores the min-heap property. Assumes that at the time of call, the min-heap property holds everywhere, with the possible exception of one position and its children.

Specified by:
heapify in class Heap
Parameters:
i - Index of the position at which the min-heap property might not hold.