home *** CD-ROM | disk | FTP | other *** search
- #define ULONG unsigned long
-
-
- static short (*_comp)();
- static void (*_swap)();
-
- static ULONG _rearr(lb,ub)
- register ULONG lb, ub;
- {
-
- do {
- while( ub > lb && (*_comp)(ub, lb) >= 0)
- ub--;
- if( ub != lb )
- {
- (*_swap)(ub,lb);
- while(lb < ub && (*_comp)(lb,ub) <= 0)
- lb++;
- if( lb != ub )
- (*_swap)(lb, ub);
- }
- } while( lb != ub );
-
- return(lb);
- }
-
-
- static void _quick(lb, ub)
- register ULONG lb, ub;
- {
- register ULONG j;
-
- if( lb < ub )
- {
- if( j = _rearr(lb, ub))
- _quick(lb,j - 1L);
- _quick(j + 1L, ub);
- }
- }
-
-
- void quicksort(n,comp,swap)
- register ULONG n;
- short (*comp)();
- void (*swap)();
- {
- _comp = comp;
- _swap = swap;
- _quick((ULONG)0,(ULONG)(n - 1));
- }
-
-
-