5.5 Sorting functions

Sorting can be used to sort values or the indices of those values in either ascending or descending order. For example, if v is declared as a real array of size 3, with values \[ \text{v} = (1, -10.3, 20.987), \] then the various sort routines produce \[\begin{eqnarray*} \mathrm{sort\_asc(v)} & = & (-10.3,1,20.987) \\[4pt] \mathrm{sort\_desc(v)} & = & (20.987,1,-10.3) \\[4pt] \mathrm{sort\_indices\_asc(v)} & = & (2,1,3) \\[4pt] \text{sort\_indices\_desc(v)} & = & (3,1,2) \end{eqnarray*}\]

array[] real sort_asc(array[] real v)
Sort the elements of v in ascending order
Available since 2.0

array[] int sort_asc(array[] int v)
Sort the elements of v in ascending order
Available since 2.0

array[] real sort_desc(array[] real v)
Sort the elements of v in descending order
Available since 2.0

array[] int sort_desc(array[] int v)
Sort the elements of v in descending order
Available since 2.0

array[] int sort_indices_asc(array[] real v)
Return an array of indices between 1 and the size of v, sorted to index v in ascending order.
Available since 2.3

array[] int sort_indices_asc(array[] int v)
Return an array of indices between 1 and the size of v, sorted to index v in ascending order.
Available since 2.3

array[] int sort_indices_desc(array[] real v)
Return an array of indices between 1 and the size of v, sorted to index v in descending order.
Available since 2.3

array[] int sort_indices_desc(array[] int v)
Return an array of indices between 1 and the size of v, sorted to index v in descending order.
Available since 2.3

int rank(array[] real v, int s)
Number of components of v less than v[s]
Available since 2.0

int rank(array[] int v, int s)
Number of components of v less than v[s]
Available since 2.0