Up: Sorting Functions   [Contents][Index]


21.10.1 qsort

The standard function qsort has the following prototype:

fun qsort = (any[] array, Comparator cmp_f,
               long left = 0,
               long right = array'length - 1) void

where array is the array to sort, cmp_f is a comparator function, left is the index of the first array element to include in the sorting, and right is the index of the last array element to include in the sorting. Both left and right are optional, and the default is to cover the whole array.

The comparator function cmp_f should have the following prototype:

type Comparator = (any,any)int<32>;

for example:

fun CompareInts = (any a, any b) int<32>:
{
  var ai = a as int<32>;
  var bi = b as int<32>;

  if (ai == bi)
    return 0;
  else if (ai > bi)
    return 1;
  else
    return -1;
}