net.sf.jsort.sort
Class HeapSort

java.lang.Object
  extended by net.sf.jsort.sort.AbstractSort
      extended by net.sf.jsort.sort.HeapSort
All Implemented Interfaces:
CompareSort, SortAlgorithm

public final class HeapSort
extends AbstractSort

This is a implemention of the Heap Sort algorithm.

This algorithm use the structure of a tree inside the array, it manipulate any element using the concept of methods parent(), left() and right(). The main method of this algorithm is maxHeapify(), it keeps the parent (position i) and its children under the rule parent(i) >= i. This rule is used by PriorityQueue to keep with a very simple implementation the hole queue ordered.

Author:
Domingos Creado
See Also:
http://en.wikipedia.org/wiki/Heapsort

Constructor Summary
HeapSort()
           
 
Method Summary
 void buildMaxHeap(java.lang.Object[] a, java.util.Comparator comparator, int start, int end)
          build the heap
 void heapsort(java.lang.Object[] a, java.util.Comparator comparator, int start, int end)
           
 void sort(java.lang.Object[] list, java.util.Comparator comparator, int start, int end)
          Sort a specific range of the list, using the specified comparator.
 
Methods inherited from class net.sf.jsort.sort.AbstractSort
sort, sort, sort, sort, sort, sort, sort
 
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 void sort(java.lang.Object[] list,
                 java.util.Comparator comparator,
                 int start,
                 int end)
Description copied from interface: CompareSort
Sort a specific range of the list, using the specified comparator.

Specified by:
sort in interface CompareSort
Specified by:
sort in class AbstractSort
Parameters:
list - to be sort

heapsort

public void heapsort(java.lang.Object[] a,
                     java.util.Comparator comparator,
                     int start,
                     int end)

buildMaxHeap

public void buildMaxHeap(java.lang.Object[] a,
                         java.util.Comparator comparator,
                         int start,
                         int end)
build the heap

Parameters:
a -
comparator -


Copyright © 2005-2008 Domingos Creado. All Rights Reserved.