org.xith3d.utility.comparator
Class Sorter

java.lang.Object
  extended by org.xith3d.utility.comparator.Sorter

public final class Sorter
extends java.lang.Object

Holds static methods to sort lists


Method Summary
static
<E extends org.jagatoo.datatypes.Chainable<E>>
E
mergeSort(E head, java.util.Comparator<E> comp)
          This is a generic merge sort algorithm, that sorts a linked list.
static
<E> void
quickSort(E[] a, int lo0, int hi0, java.util.Comparator<E> comp)
          This is a generic version of C.A.R Hoare's Quick Sort algorithm.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

quickSort

public static <E> void quickSort(E[] a,
                                 int lo0,
                                 int hi0,
                                 java.util.Comparator<E> comp)
This is a generic version of C.A.R Hoare's Quick Sort algorithm. This will handle arrays that are already sorted, and arrays with duplicate keys.
If you think of a one dimensional array as going from the lowest index on the left to the highest index on the right then the parameters to this function are lowest index or left and highest index or right. The first time you call this function it will be with the parameters 0, a.length - 1.

Parameters:
a - an object array
lo0 - left boundary of array partition
hi0 - right boundary of array partition
comp - the comparator used

mergeSort

public static <E extends org.jagatoo.datatypes.Chainable<E>> E mergeSort(E head,
                                                                         java.util.Comparator<E> comp)
This is a generic merge sort algorithm, that sorts a linked list.

It is a ported version of the one that I found on http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html

Type Parameters:
E - the type of the elements to be sorted
Parameters:
head - the head of the linked list
comp - the Comparator to compare the elements
Returns:
the new head of the linked list