ISORT, SSORT, and DSORT (Sort the Elements of a Sequence)

Purpose

These subroutines sort the elements of sequence x.
Table 1. Data Types
Data Types
x Subroutine
Integer ISORT
Short-precision real SSORT
Long-precision real DSORT

Syntax

Language Syntax
Fortran CALL ISORT | SSORT | DSORT (x, incx, n)
C and C++ isort | ssort | dsort (x, incx, n);
On Entry
x
is the sequence x of length n, to be sorted.
Specified as: a one-dimensional array of (at least) length 1+(n-1)|incx|, containing numbers of the data type indicated in Table 1.
incx
is the stride for both the input sequence x and the output sequence x. If it is positive, elements are sorted into ascending order in the array, and if it is negative, elements are sorted into descending order in the array.

Specified as: an integer. It can have any value.

n
is the number of elements in sequence x. Specified as: an integer; n0.
On Return
x
is the sequence x of length n, with its elements sorted into designated order in the array. Returned as: a one-dimensional array, containing numbers of the data type indicated in Table 1.

Function

The elements of input sequence x are sorted into ascending order, in place and using a partition sort. The elements of output sequence x can be expressed as follows:

x1x2x3xn

By specifying a negative stride for sequence x, the elements of sequence x are assumed to be reversed in the array, (xn, xn-1, , x1), thus producing a sort into descending order within the array. If n is 0 or 1 or if incx is 0, no sort is performed. See reference [91].

Error conditions

Resource Errors
Unable to allocate internal work area.
Computational Errors
None
Input-Argument Errors
n < 0

Examples

Example 1

This example shows a sequence x with a positive stride.

Call Statement and Input:

            X  INCX  N
            |   |    |
CALL ISORT( X , 2  , 5 )
 
X        =  (2, . , -1, . , 5, . , 4, . , -2)

Output:

X        =  (-2, . , -1, . , 2, . , 4, . , 5)
Example 2

This example shows a sequence x with a negative stride.

Call Statement and Input:

            X   INCX  N
            |    |    |
CALL ISORT( X , -1  , 5 )
 
X        =  (2, -1, 5, 4, -2)

Output:

X        =  (5, 4, 2, -1, -2)