DataStructures
Class Sort

java.lang.Object
  |
  +--DataStructures.Sort

public final class Sort
extends java.lang.Object

A class that contains several sorting routines, implemented as static methods. Arrays are rearranged with smallest item first, using compareTo.


Constructor Summary
Sort()
           
 
Method Summary
static void heapsort(Comparable[] a)
          Standard heapsort.
static void insertionSort(Comparable[] a)
          Simple insertion sort.
static void main(java.lang.String[] args)
           
static void mergeSort(Comparable[] a)
          Mergesort algorithm.
static void quickSelect(Comparable[] a, int k)
          Quick selection algorithm.
static void quicksort(Comparable[] a)
          Quicksort algorithm.
static void shellsort(Comparable[] a)
          Shellsort, using Shell's (poor) increments.
static void swapReferences(java.lang.Object[] a, int index1, int index2)
          Method to swap to elements in an array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Sort

public Sort()
Method Detail

insertionSort

public static void insertionSort(Comparable[] a)
Simple insertion sort.
Parameters:
a - an array of Comparable items.

shellsort

public static void shellsort(Comparable[] a)
Shellsort, using Shell's (poor) increments.
Parameters:
a - an array of Comparable items.

heapsort

public static void heapsort(Comparable[] a)
Standard heapsort.
Parameters:
a - an array of Comparable items.

mergeSort

public static void mergeSort(Comparable[] a)
Mergesort algorithm.
Parameters:
a - an array of Comparable items.

quicksort

public static void quicksort(Comparable[] a)
Quicksort algorithm.
Parameters:
a - an array of Comparable items.

swapReferences

public static final void swapReferences(java.lang.Object[] a,
                                        int index1,
                                        int index2)
Method to swap to elements in an array.
Parameters:
a - an array of objects.
index1 - the index of the first object.
index2 - the index of the second object.

quickSelect

public static void quickSelect(Comparable[] a,
                               int k)
Quick selection algorithm. Places the kth smallest item in a[k-1].
Parameters:
a - an array of Comparable items.
k - the desired rank (1 is minimum) in the entire array.

main

public static void main(java.lang.String[] args)