    All Packages  Class Hierarchy  This Package  Previous  Next  Index

# Class DataStructures.Sort

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

public final class Sort
extends Object

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

##

Sort()

##

heapsort(Comparable[])
  Standard heapsort.
insertionSort(Comparable[])
  Simple insertion sort.
mergeSort(Comparable[])
  Mergesort algorithm.
quickSelect(Comparable[], int)
  Quick selection algorithm.
quicksort(Comparable[])
  Quicksort algorithm.
shellsort(Comparable[])
  Shellsort, using a sequence suggested by Gonnet.
swapReferences(Object[], int, int)
  Method to swap to elements in an array.

##

Sort

    public Sort()

##

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 a sequence suggested by Gonnet.

  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 void swapReferences(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.

    All Packages  Class Hierarchy  This Package  Previous  Next  Index