Xar module

quick_sort

procedureSource

Sorts in place with a three-way comparator (negative, zero or positive). Despite the name it is an unstable heap sort, O(n log n); it returns nothing and has no key form.

Example↗
array: Xar(int, 2, 4);
for value: int.[3, 1, 2] xar_add(*array, value);
quick_sort(array, (a: int, b: int) -> int { return a - b; });
assert(array[0] == 1 && array[2] == 3);
xar_reset(*array);
quick_sort :: (array: $T/Xar, f: (T.Element_Type, T.Element_Type) -> $R)

All three public names are this one heap sort.

Parameters

array: $T/Xar
f: (T.Element_Type, T.Element_Type) -> $R

See also