Output of file : QSORT.C contained in archive : SDB.ZIP
/* qsort - quick sort routine */

/* translated to C from the 'Software Tools in Pascal' routines
by Kernighan & Plauger
*/

/* qsort - quick sort routine */
qsort(linepos,nlines,cmprec)
char *linepos[]; int nlines; int (*cmprec)();
{
qsort1(linepos,0,nlines-1,cmprec);
}

/* qsort1 - the real sort routine */
static qsort1(linepos,lo,hi,cmprec)
char *linepos[]; int lo,hi; int (*cmprec)();
{
char *pivline;
int i,j;

/* make sure there's something to sort */
if (lo >= hi)
return;

/* initialize */
i = lo;
j = hi;
pivline = linepos[j];

/* partition the set */
do {
while (i < j && (*cmprec)(linepos[i],pivline) <= 0)
i++;
while (j > i && (*cmprec)(linepos[j],pivline) >= 0)
j--;
if (i < j)
exchange(linepos,i,j);
} while (i < j);

/* move pivot to i */
exchange(linepos,i,hi);

/* sort each partition */
if (i - lo < hi - i) {
qsort1(linepos,lo,i-1,cmprec);
qsort1(linepos,i+1,hi,cmprec);
}
else {
qsort1(linepos,i+1,hi,cmprec);
qsort1(linepos,lo,i-1,cmprec);
}
}

/* exchange - exchange two lines */
static exchange(linepos,l1,l2)
char *linepos[]; int l1,l2;
{
char *tmp;

tmp = linepos[l1];
linepos[l1] = linepos[l2];
linepos[l2] = tmp;
}

### 3 Responses to “Category : C Source CodeArchive   : SDB.ZIPFilename : QSORT.C”

1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/