-
Notifications
You must be signed in to change notification settings - Fork 2
System.Sort
Dennis G. edited this page Jun 9, 2026
·
3 revisions
function Sort(Values: array, Sorter: function): array = \built-in\
The Sort function in the System package sorts an existing array using a comparer function.
The second parameter is a function accepting two parameters and returning a signed integer number. Its result should be depending on the two parameters passed:
-
-1or any other negative number if the first argument is less than the second -
0if the first and second argument are equal (or equivalent) -
1or any positive number if the first argument is greater than the second
Because the function uses the Quicksort algorithm, the average call produces O(n * Log(n)) comparisons, the actual amount depending on the input array.
- If the length of
Valuesis0,Sorteris never called and an empty array ([]) or record ({}) is returned. - If the length of
Valuesis1,Sorteris never called and the input array is returned without modifications. - If
Sorterdemands more or less arguments than2, an exception is raised.
Texts, images and code samples on this page are available under MPL 2.0 license