4.2.1.4. Array sorting operations

In this section: arg_sort, sort, sort_by.

arg_sort

function array [int] of $$E: arg_sort(array [$$E] of int: x)
function array [int] of $$E: arg_sort(array [$$E] of float: x)

Returns the permutation p which causes x to be in sorted order hence x[p[i]] <= x[p[i+1]].

The permutation is the stable sort hence x[p[i]] = x[p[i+1]] \(\rightarrow\) p[i] < p[i+1].

sort

function array [$$E] of int: sort(array [$$E] of int: x)
function array [$$E] of float: sort(array [$$E] of float: x)
function array [$$E] of bool: sort(array [$$E] of bool: x)

Return values from array x sorted in non-decreasing order

sort_by

function array [$$E] of any $T: sort_by(array [$$E] of any $T: x,
                                        array [$$E] of int: y)
function array [$$E] of any $T: sort_by(array [$$E] of any $T: x,
                                        array [$$E] of float: y)

Return array x sorted by the values in y in non-decreasing order

The sort is stable, i.e. if y[i] = y[j] with i < j, then x[i] will appear in the output before x[j].