maspack.util
Class ArraySort

java.lang.Object
  extended by maspack.util.ArraySort

public class ArraySort
extends java.lang.Object

Support class for sorting arrays of integers and doubles. The code for quicksort was based on information provided in the wikipedia entry for quicksort.


Constructor Summary
ArraySort()
           
 
Method Summary
static void bubbleSort(int[] keys)
          Performs a bubble sort on an array of integers into ascending order.
static void bubbleSort(int[] keys, double[] vals)
          Performs a bubble sort on an array of integers into ascending order, and correspondingly rearranges an accompanying array of values.
static void bubbleSort(int[] keys, double[] vals, int left, int right)
          Performs a bubble sort on a subregion of an array of integers into ascending order, and correspondingly rearranges the same subregion of an accompanying array of values.
static void bubbleSort(int[] keys, int left, int right)
          Performs a bubble sort on a subregion of an array of integers into ascending order.
static void quickSort(double[] vals)
          Performs a quicksort on an array of doubles into ascending order.
static void quickSort(double[] vals, int[] keys)
          Performs a quicksort on an array of doubles into ascending order, and correspondingly rearranges an accompanying array of integer keys.
static void quickSort(double[] vals, int[] keys, int left, int right)
          Performs a quicksort on a subregion of an array of doubles into ascending order, and correspondingly rearranges the same subregion of an accompanying array of keys.
static void quickSort(double[] vals, int left, int right)
          Performs a quicksort on a subregion of an array of doubles into ascending order.
static void quickSort(int[] keys)
          Performs a quicksort on an array of integers into ascending order.
static void quickSort(int[] keys, double[] vals)
          Performs a quicksort on an array of integers, into ascending order, and correspondingly rearranges an accompanying array of values.
static void quickSort(int[] keys, double[] vals, int left, int right)
          Performs a quicksort on a subregion of an array of integers into ascending order, and correspondingly rearranges the same subregion of an accompanying array of values.
static void quickSort(int[] keys, int left, int right)
          Performs a quicksort on a subregion of an array of integers into ascending order.
static void sort(int[] keys)
          Sorts an array of integers into ascending order.
static void sort(int[] keys, double[] vals)
          Sorts an array of integers into ascending order, and correspondingly rearranges an accompanying array of values.
static void sort(int[] keys, double[] vals, int left, int right)
          Sorts a subregion of an array of integers into ascending order, and correspondingly rearranges the same subregion of an accompanying array of values.
static void sort(int[] keys, int left, int right)
          Sorts a subregion of an array of integers into ascending order.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArraySort

public ArraySort()
Method Detail

sort

public static void sort(int[] keys)
Sorts an array of integers into ascending order. The method chooses between quicksort and bubble sort depending on the size of the input.

Parameters:
keys - integers to sort

sort

public static void sort(int[] keys,
                        int left,
                        int right)
Sorts a subregion of an array of integers into ascending order. The subregion is defined by left <= i <= right. The method chooses between quicksort and bubble sort depending on the size of the input.

Parameters:
keys - integers containing the subregion to sort
left - lower inclusive bound of the subregion
right - upper inclusive bound of the subregion

sort

public static void sort(int[] keys,
                        double[] vals)
Sorts an array of integers into ascending order, and correspondingly rearranges an accompanying array of values. The method chooses between quicksort and bubble sort depending on the size of the input.

Parameters:
keys - integers to sort
vals - accompanying values to be sorted into the same order as keys. Must have a length at least as long as keys.

sort

public static void sort(int[] keys,
                        double[] vals,
                        int left,
                        int right)
Sorts a subregion of an array of integers into ascending order, and correspondingly rearranges the same subregion of an accompanying array of values. The subregion is defined by left <= i <= right. The method chooses between quicksort and bubble sort depending on the size of the input.

Parameters:
keys - integers containing the subregion to sort
vals - accompanying values, whose equivalent subregion is sorted into the same order as the subregion as keys. Must be long enough to encompass the subregion.
left - lower inclusive bound of the subregion
right - upper inclusive bound of the subregion

bubbleSort

public static void bubbleSort(int[] keys)
Performs a bubble sort on an array of integers into ascending order.

Parameters:
keys - integers to sort

bubbleSort

public static void bubbleSort(int[] keys,
                              int left,
                              int right)
Performs a bubble sort on a subregion of an array of integers into ascending order. The subregion is defined by left <= i <= right.

Parameters:
keys - integers containing the subregion to sort
left - lower inclusive bound of the subregion
right - upper inclusive bound of the subregion

bubbleSort

public static void bubbleSort(int[] keys,
                              double[] vals)
Performs a bubble sort on an array of integers into ascending order, and correspondingly rearranges an accompanying array of values.

Parameters:
keys - integers to sort
vals - accompanying values to be sorted into the same order as keys. Must have a length at least as long as keys.

bubbleSort

public static void bubbleSort(int[] keys,
                              double[] vals,
                              int left,
                              int right)
Performs a bubble sort on a subregion of an array of integers into ascending order, and correspondingly rearranges the same subregion of an accompanying array of values. The subregion is defined by left <= i <= right.

Parameters:
keys - integers containing the subregion to sort
vals - accompanying values, whose equivalent subregion is sorted into the same order as the subregion as keys. Must be long enough to encompass the subregion.
left - lower inclusive bound of the subregion
right - upper inclusive bound of the subregion

quickSort

public static void quickSort(int[] keys,
                             int left,
                             int right)
Performs a quicksort on a subregion of an array of integers into ascending order. The subregion is defined by left <= i <= right.

Parameters:
keys - integers containing the subregion to sort
left - lower inclusive bound of the subregion
right - upper inclusive bound of the subregion

quickSort

public static void quickSort(int[] keys)
Performs a quicksort on an array of integers into ascending order.

Parameters:
keys - integers to sort

quickSort

public static void quickSort(int[] keys,
                             double[] vals,
                             int left,
                             int right)
Performs a quicksort on a subregion of an array of integers into ascending order, and correspondingly rearranges the same subregion of an accompanying array of values. The subregion is defined by left <= i <= right.

Parameters:
keys - integers containing the subregion to sort
vals - accompanying values, whose equivalent subregion is sorted into the same order as the subregion as keys. Must be long enough to encompass the subregion.
left - lower inclusive bound of the subregion
right - upper inclusive bound of the subregion

quickSort

public static void quickSort(int[] keys,
                             double[] vals)
Performs a quicksort on an array of integers, into ascending order, and correspondingly rearranges an accompanying array of values.

Parameters:
keys - integers to sort
vals - accompanying values to be sorted into the same order as keys. Must have a length at least as long as keys.

quickSort

public static void quickSort(double[] vals,
                             int left,
                             int right)
Performs a quicksort on a subregion of an array of doubles into ascending order. The subregion is defined by left <= i <= right.

Parameters:
vals - doubles containing the subregion to sort
left - lower inclusive bound of the subregion
right - upper inclusive bound of the subregion

quickSort

public static void quickSort(double[] vals)
Performs a quicksort on an array of doubles into ascending order.

Parameters:
vals - values to sort

quickSort

public static void quickSort(double[] vals,
                             int[] keys,
                             int left,
                             int right)
Performs a quicksort on a subregion of an array of doubles into ascending order, and correspondingly rearranges the same subregion of an accompanying array of keys. The subregion is defined by left <= i <= right.

Parameters:
vals - array of values containing the subregion to sort
keys - accompanying keys, whose equivalent subregion is sorted into the same order as the subregion of vals. Must be long enough to encompass the subregion.
left - lower inclusive bound of the subregion
right - upper inclusive bound of the subregion

quickSort

public static void quickSort(double[] vals,
                             int[] keys)
Performs a quicksort on an array of doubles into ascending order, and correspondingly rearranges an accompanying array of integer keys.

Parameters:
vals - values to sort
keys - accompanying keys to be sorted into the same order as vals. Must have a length at least as long as vals.