com.mhhe.clrs2e
Class MaxHeap

java.lang.Object
  |
  +--com.mhhe.clrs2e.Heap
        |
        +--com.mhhe.clrs2e.MaxHeap
Direct Known Subclasses:
MaxHeapPriorityQueue

public class MaxHeap
extends Heap

Implements a binary max-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) MaxHeap()
          Creates an empty max-heap.
(package private) MaxHeap(java.lang.Comparable[] array)
          Makes a max-heap in place from the argument, and ensures that the max-heap property holds.
 
Method Summary
 void heapify(int i)
          Restores the max-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

MaxHeap

MaxHeap()
Creates an empty max-heap.


MaxHeap

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

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

heapify

public void heapify(int i)
Restores the max-heap property. Assumes that at the time of call, the max-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 max-heap property might not hold.