QUICKSORTX performs a quick-sort of an array by using a
specified compare function.
>>-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:
- If the value of the first array element is less than the value
of the second array element, then the returned value must be -1.
- If the value of the first array element is equal to the value
of the second array element, then the returned value must be 0.
- If the value of the first array element is greater than the value
of the second array element, then the returned value must be +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:
- if j < k, thenf( addr(x(j)), addr(x(k))
) < = 0