Reference Guide > S Routines > SORT Function
  

SORT Function
Sorts the contents of an array.
Usage
result = SORT(array)
Input Parameters
array—The vector or array to be sorted.
Returned Value
result—A vector of subscripts which allow access to the elements of array in ascending order.
Keywords
None.
Discussion
String arrays are sorted using the ASCII collating sequence. The result is a vector of type LONG with the same number of elements as array.
The contents of the result are the sorted indices, not the values themselves.
Example
This example uses SORT to obtain the vector of subscripts that places the single-precision, floating-point vector a into ascending order. To obtain elements of a in sorted order, use the vector of subscripts returned by SORT as the subscript vector for a.
; Create an unsorted single-precision, floating-point vector.
a = [4.0, 3.0, 7.0, 1.0, 2.0]
; Place the vector of sorting subscripts into b.
b = SORT(a)
PRINT, b
; PV-WAVE prints: 3    4    1    0    2
; Print sorted vector by using b as the subscript vector for a.
PRINT, a(b)
; PV-WAVE prints: 1.00000 2.00000 3.00000 4.00000 7.00000
See Also
AVG, MAX, MIN, MEDIAN, QUERY_TABLE, SORTDIM, SORTN, UNIQUE, WHERE

Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.