M101: Sort One-Dimensional Array
Author(s): H. von Eicken | Library: KERNLIB
|
Submitter: | Submitted: 14.08.1985
|
Language: CDC: Compass, IBM: Fortran | Revised:
|
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:
Integer,
Hollerith,
Real.
- NWAY
- Order of sort:
Ascending order,
Descending order.
- NSORT
- Elements to be sorted:
Sort the first N elements of A,
Sort N words of A as indicated by array
INDEX.
- M
- Character set to be used: (CDC only)
Use display code (only applicable to Hollerith sort),
Use collating sequence specified in CARSET
.
- 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:
- 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.
- 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:
- R.S. Scowen, Algorithm 271 QUICKERSORT, Collected Algorithms
from CACM (1965).
Michel Goossens
Wed Jun 5 07:00:26 METDST 1996