next up previous index
Next: M103 Sort One-Dimensional Up: CERNLIB Previous: L400 Source Code

M101 Sort One-Dimensional Array

Routine ID: M101
Author(s): H. von EickenLibrary: KERNLIB
Submitter: Submitted: 14.08.1985
Language: CDC: Compass, IBM: FortranRevised:

SORTZV will sort a one-dimensional array containing Hollerith or numerical integer or real information. The user may specify his own collating sequence for characters; otherwise that of the display code will be used. The array to be sorted is not changed. The output of SORTZV is an integer array containing the ordered indices indicating the order of the original array (see Examples).

Structure:

SUBROUTINE subprogram
User Entry Names: SORTZV

Usage:

CDC:

    CALL SORTZV(A,INDEX,N,MODE,NWAY,NSORT,M,CARSET)
Others:
    CALL SORTZV(A,INDEX,N,MODE,NWAY,NSORT)
A
One-dimensional array of elements to be sorted.
INDEX
One-dimensional array of indices. After execution it contains the indices denoting the desired order of A. On input it may contain (depending on NSORT) indices denoting which elements of A are to be sorted (see Examples).
N
Number of words to be sorted.
MODE
Type of sort required:
< 0: Integer,
= 0: Hollerith,
> 0: Real.
NWAY
Order of sort:
= 0: Ascending order,
≠0: Descending order.
NSORT
Elements to be sorted:
= 0: Sort the first N elements of A,
≠0: Sort N words of A as indicated by array INDEX.
M
Character set to be used: (CDC only)
= 0: Use display code (only applicable to Hollerith sort),
= K: Use collating sequence specified in CARSET (K ≤64) .
CARSET
Defines the collating sequence for a Hollerith sort. This array must be at least 64 elements in length. On entering SORTZV the K characters for which the user wishes to specify the order, must be in the first K words of CARSET (one character/word, left-adjusted and blank-filled). Any characters found during the sort which have not been defined in CARSET will be added to CARSET.

Restrictions:

The input order of equal elements is not necessarily retained. The parameters M and CARSET are only used in the CDC version.

Examples:

  1. Assume the array I contains 0,1,-1,4,-2,0,4,5,7,8. Then the statement
        CALL SORTZV(I,INDEX,5,-1,0,0)
    
    ( M and CARSET omitted) sets the array INDEX to 5,3,1,2,4.
  2. With the same array I and the array INDEX containing 1,3,5,6,7,8,
        CALL SORTZV(I,INDEX,6,-1,0,1)
    
    sets the array INDEX to 5,3,1,6,7,8.
For more details, see Long Write-up.

Based on an Algol procedure described in Ref. 1.

References:

  1. R.S. Scowen, Algorithm 271 QUICKERSORT, Collected Algorithms from CACM (1965).

M103



next up previous index
Next: M103 Sort One-Dimensional Up: CERNLIB Previous: L400 Source Code


Janne Saarela
Mon Apr 3 15:06:23 METDST 1995