algs.model.heap
Class HeapSort<E>
java.lang.Object
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
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 |
HeapSort
public HeapSort()
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 objectsleft
- 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 objectsleft
- 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.
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.