Performs a quick-sort of an array by using a specified compare.
QUICKSORTX( x,f)
f must:
dcl arr (5) fixed bin (31) init (1,4,3,2,5); dcl el entry limited; el = func; call quicksortx(arr, el); /* same as quicksort. Ascending order */ put skip list (arr); / * 1 2 3 4 5 */ el = func1; call quicksortx(arr, el); /* quicksort reversed, Descending order */ put skip list (arr); /* 5 4 3 2 1 */ /* ascending */ func: proc (p, q) returns(fixed bin (31) ); dcl (p, q) pointer byvalue; dcl x fixed bin (31) based(p); dcl y fixed bin (31) based(q); /* asecending order */ if x > y then return(1); if x = y then return(0); return (-1); end; /* descending */ func1: proc (p, q) returns(fixed bin (31) ); dcl (p, q) pointer byvalue; dcl x fixed bin (31) based(p); dcl y fixed bin (31) based(q); /* decending order */ if x > y then return(-1); if x = y then return(0); return (1); end;
Description
The QUICKSORTX built-in subroutine performs a quick-sort, overwriting x with the sorted elements. The sorted array elements are stored in accordance with the result of the comparison function.
For example, you can sort in reverse order by reversing the less-than and greater-than logic in the comparison function.
If the result of the compare on two elements is equal, their order in the sorted array is unspecified.