Category : C Source Code
Archive   : C-TOOLBX.ZIP
Filename : QSORTI.C
#include "stdio.h"
#include "cminor.h"
int qsort(a,na)
int a[] ; /* array of integers to be sorted */
int na ; /* number of elements to be sorted */
{
int i , j ; /* indices for loops */
int temp ; /* temporary storage for element */
int nr ; /* number elements in right partition */
int part ; /* element chosen as partition value */
if( na < 2 )
return ;
part = a[na/2] ; /* pick middle element for partition */
i = -1 ; j = na ;
while( 1 ==1 )
{ /* find first element to move right */
do { i = i + 1 ; } while( a[i] < part ) ;
/* find first element to move left */
do { j = j - 1 ; } while( a[j] > part ) ;
if( i >= j ) /* have the boundries met ? */
break ; /* yes - through partitioning */
/* swap i and j elements */
temp = a[i] ; a[i] = a[j] ; a[j] = temp ;
}
nr = na - 1 ;
if( i < (na/2) ) /* now deal with each partition */
{ qsort( a , i ) ; /* sort left side */
qsort( &(a[i]),nr) ; /* sort right side */
}
else
{ qsort( &(a[i]),nr) ; /* sort right side */
qsort( a , i ) ; /* sort left side */
}
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
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/