IBM Books

Engineering and Scientific Subroutine Library for AIX Version 3 Release 3: Guide and Reference

ISORT, SSORT, and DSORT--Sort the Elements of a Sequence

These subroutines sort the elements of sequence x.

Table 149. Data Types

x Subroutine
Integer ISORT
Short-precision real SSORT
Long-precision real DSORT

Syntax

Fortran CALL ISORT | SSORT | DSORT (x, incx, n)
C and C++ isort | ssort | dsort (x, incx, n);
PL/I CALL 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 149.

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: a fullword integer. It can have any value.

n
is the number of elements in sequence x. Specified as: a fullword integer; n >= 0.

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 149.

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:

x1 <= x2 <= x3 <= ... <= xn

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 [75].

Error Conditions

Resource Errors

Unable to allocate internal work area.

Computational Errors

None

Input-Argument Errors

n < 0

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)


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]