home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Oakland CPM Archive
/
oakcpm.iso
/
cpm
/
bdsc-4
/
bdslib.ark
/
QSORT.C
< prev
next >
Wrap
Text File
|
1983-07-15
|
896b
|
38 lines
/*
* qsort
* This function is exactly as documented in the BDS C Version
* 1.5 Users Manual and as swiped from K & P.
*/
#define MAX_QSORT_WIDTH 513 /* Largest object qsort can sort */
qsort(base, nel, width, compar)
char *base; int (*compar)();
unsigned width,nel;
{ int i, j;
unsigned gap, ngap, t1;
int jd, t2;
t1 = nel * width;
for (ngap = nel / 2; ngap > 0; ngap /= 2) {
gap = ngap * width;
t2 = gap + width;
jd = base + gap;
for (i = t2; i <= t1; i += width)
for (j = i - t2; j >= 0; j -= gap) {
if ((*compar)(base+j, jd+j) <=0) break;
_swp(width, base+j, jd+j);
}
}
}
_swp(w,a,b)
char *a,*b;
unsigned w;
{
char swapbuf[MAX_QSORT_WIDTH];
movmem(a,swapbuf,w);
movmem(b,a,w);
movmem(swapbuf,b,w);
}