JMSLTM Numerical Library 4.0

com.imsl.stat
Class Sort

java.lang.Object
  extended bycom.imsl.stat.Sort

public class Sort
extends Object

A collection of sorting functions.

Class Sort contains ascending and descending methods for sorting elements of an array or a matrix. The array ascending method sorts the elements of an array, A, into ascending order by algebraic value. The array A is divided into two parts by picking a central element T of the array. The first and last elements of A are compared with T and exchanged until the three values appear in the array in ascending order. The elements of the array are rearranged until all elements greater than or equal to the central element appear in the second part of the array and all those less than or equal to the central element appear in the first part. The upper and lower subscripts of one of the segments are saved, and the process continues iteratively on the other segment. When one segment is finally sorted, the process begins again by retrieving the subscripts of another unsorted portion of the array. On completion, A_j le A_i for j lt i. For more details, see Singleton (1969), Griffin and Redish (1970), and Petro (1970).

The matrix ascending method sorts the rows of real matrix x using a particular row in x as the keys. The sort is algebraic with the first key as the most significant, the second key as the next most significant, etc. When x is sorted in ascending order, the resulting sorted array is such that the following is true:

The observations also can be sorted in descending order.

The rows of x containing the missing value code NaN in at least one of the specified columns are considered as an additional group. These rows are moved to the end of the sorted x. The sorting algorithm is based on a quicksort method given by Singleton (1969) with modifications by Griffen and Redish (1970) and Petro (1970).

All other methods in this class work off of the ascending methods.

See Also:
Example, Example

Constructor Summary
Sort()
           
 
Method Summary
static void ascending(double[] ra)
          Sort an array into ascending order.
static void ascending(double[][] ra, int nKeys)
          Sort a matrix into ascending order by specified keys.
static void ascending(double[][] ra, int[] indkeys)
          Sort a matrix into ascending order by specified keys.
static void ascending(double[][] ra, int[] indkeys, int[] iperm)
          Sort a matrix into ascending order by specified keys.
static void ascending(double[][] ra, int nKeys, int[] iperm)
          Sort an array into ascending order by specified keys.
static void ascending(double[] ra, int[] iperm)
          Sort an array into ascending order.
static void ascending(int[] ra)
          Function to sort an integer array into ascending order.
static void ascending(int[] ra, int[] iperm)
          Sort an array into ascending order.
static void descending(double[] ra)
          Sort an array into descending order.
static void descending(double[][] ra, int nKeys)
          Function to sort a matrix into descending order by specified keys.
static void descending(double[][] ra, int[] indkeys)
          Function to sort a matrix into descending order by specified keys.
static void descending(double[][] ra, int[] indkeys, int[] iperm)
          Function to sort a matrix into descending order by specified keys.
static void descending(double[][] ra, int nKeys, int[] iperm)
          Function to sort an array into descending order by specified keys.
static void descending(double[] ra, int[] iperm)
          Sort an array into descending order.
 
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

ascending

public static void ascending(double[] ra)
Sort an array into ascending order.

Parameters:
ra - double array to be sorted into ascending order

ascending

public static void ascending(double[][] ra,
                             int nKeys)
Sort a matrix into ascending order by specified keys.

Parameters:
ra - double matrix to be sorted into ascending order.
nKeys - int containing the first nKeys columns of ra to be used as the sorting keys.

ascending

public static void ascending(double[][] ra,
                             int[] indkeys)
Sort a matrix into ascending order by specified keys.

Parameters:
ra - double matrix to be sorted into ascending order.
indkeys - int array containing the order the columns of ra are to be sorted.

ascending

public static void ascending(double[][] ra,
                             int[] indkeys,
                             int[] iperm)
Sort a matrix into ascending order by specified keys.

Parameters:
ra - double matrix to be sorted into ascending order.
indkeys - int array containing the order the columns of ra are to be sorted.
iperm - int array specifying the rearrangement (permutation) of the observations (rows) of ra.

ascending

public static void ascending(double[][] ra,
                             int nKeys,
                             int[] iperm)
Sort an array into ascending order by specified keys.

Parameters:
ra - double array to be sorted into ascending order.
nKeys - int containing the first nKeys columns of ra to be used as the sorting keys.
iperm - int array specifying the rearrangement (permutation) of the observations (rows) of ra.

ascending

public static void ascending(double[] ra,
                             int[] iperm)
Sort an array into ascending order.

Parameters:
ra - double array to be sorted into ascending order
iperm - int array specifying the rearrangement (permutation) of the observations (rows) of ra.

ascending

public static void ascending(int[] ra)
Function to sort an integer array into ascending order.

Parameters:
ra - int array to be sorted into ascending order

ascending

public static void ascending(int[] ra,
                             int[] iperm)
Sort an array into ascending order.

Parameters:
ra - int array to be sorted into ascending order
iperm - int array to be sorted using the same permutations applied to ra. Typically, you would initialize this to 0, 1, ...

descending

public static void descending(double[] ra)
Sort an array into descending order.

Parameters:
ra - double array to be sorted into descending order

descending

public static void descending(double[][] ra,
                              int nKeys)
Function to sort a matrix into descending order by specified keys.

Parameters:
ra - double matrix to be sorted into descending order.
nKeys - int containing the first nKeys columns of ra to be used as the sorting keys.

descending

public static void descending(double[][] ra,
                              int[] indkeys)
Function to sort a matrix into descending order by specified keys.

Parameters:
ra - double matrix to be sorted into descending order.
indkeys - int array containing the order the columns of ra are to be sorted.

descending

public static void descending(double[][] ra,
                              int[] indkeys,
                              int[] iperm)
Function to sort a matrix into descending order by specified keys.

Parameters:
ra - double matrix to be sorted into descending order.
indkeys - int array containing the order the columns of ra are to be sorted.
iperm - int array specifying the rearrangement (permutation) of the observations (rows) of ra.

descending

public static void descending(double[][] ra,
                              int nKeys,
                              int[] iperm)
Function to sort an array into descending order by specified keys.

Parameters:
ra - double array to be sorted into descending order.
nKeys - int containing the first nKeys columns of ra to be used as the sorting keys.
iperm - int array specifying the rearrangement (permutation) of the observations (rows) of ra.

descending

public static void descending(double[] ra,
                              int[] iperm)
Sort an array into descending order.

Parameters:
ra - double array to be sorted into descending order
iperm - int array specifying the rearrangement (permutation) of the observations (rows) of ra.

JMSLTM Numerical Library 4.0

Copyright 1970-2006 Visual Numerics, Inc.
Built June 1 2006.