Algorithm
Development Kit 1.0

algs.model.heap
Class HeapSort<E>

java.lang.Object
  extended by algs.model.heap.HeapSort<E>
Type Parameters:
E -

public class HeapSort<E>
extends java.lang.Object

Implementation of HeapSort using BinaryHeap.

Since:
1.0
Version:
1.0, 6/15/08
Author:
George Heineman

Constructor Summary
HeapSort()
           
 
Method Summary
 boolean sort(java.lang.Comparable<E>[] ar, int left, int right)
          Sort using Heapsort method.
 boolean sort(E[] ar, int left, int right, java.util.Comparator<E> comparator)
          Sort using Heapsort method with external comparator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HeapSort

public HeapSort()
Method Detail

sort

public boolean sort(java.lang.Comparable<E>[] ar,
                    int left,
                    int right)
Sort using Heapsort method. left must be strictly less than right, otherwise return false.

Parameters:
ar - Array of Comparable objects
left - The left-bounds within which to sort (0 <= left < ar.length)
right - The right-bounds within which to sort (0 <= right < ar.length)
Returns:
false if invalid arguments passed in; true otherwise on success.

sort

public boolean sort(E[] ar,
                    int left,
                    int right,
                    java.util.Comparator<E> comparator)
Sort using Heapsort method with external comparator. left must be strictly less than right, otherwise return false.

Parameters:
ar - Array of objects
left - The left-bounds within which to sort (0 <= left < ar.length)
right - The right-bounds within which to sort (0 <= right < ar.length)
comparator - Externalize the comparison of two objects into this method.
Returns:
false if invalid arguments passed in; true otherwise on success.

Algorithm Development Kit 1.0

This code supports the Algorithms in a Nutshell book, published by O'Reilly Media, Inc. in November 2008. Please visit the book web page to learn of any changes to the code repository or to record a potential defect.