QUICKSORTX

QUICKSORTX performs a quick-sort of an array by using a specified compare function.

Read syntax diagramSkip visual syntax diagram
>>-QUICKSORTX(x,f)---------------------------------------------><

x
An array expression. x must be a one-dimensional array. If x is an array of NONVARYING BIT, it must be aligned.
f
Expression. Specifies the function that will be invoked to perform all the required comparisons.

The function f must have the OPTLINK linkage and it is passed 2 POINTER BYVALUE arguments that hold the addresses of two elements from the array x.

The function f must have the attributes RETURNS( BYVALUE FIXED BINARY(31) ), and it must return one of the values -1, 0 or +1:

The sorted array elements are stored in increasing order, in accordance with the result of the comparison function.

You can sort in reverse order by reversing the greater than and less than logic in the comparison function. If two elements are equal, their order in the sorted array is unspecified.

QUICKSORTX overwrites the contents of x with the sorted elements. When the quick-sort is finished, for elements j and k:





Published: 23 December 2018