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 $$T: xs)
function array [int] of $$E: arg_sort(array [$$E] of float: xs)

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

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

sort

function array [$$E] of $$F: sort(array [$$E] of $$F: xs)
function array [$$E] of float: sort(array [$$E] of float: xs)
function array [$$E] of bool: sort(array [$$E] of bool: xs)

Return values from array xs 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].