int Partition ( int, int, int [] ); void AuxQS ( int, int, int [] ); void QuickSort ( int [] ); int Partition ( int low, int high, int list [] ) { int numBigs = 0, numSmalls = 0, relative = list [ high], count; int *bigs, *smalls; bigs = (int*)NewPtr ( sizeof ( int ) * MAX ); smalls = (int*)NewPtr ( sizeof ( int ) * MAX ); for ( count = low; count < high; ++count ) { if ( list [ count ] > relative ) bigs [ numBigs++ ] = list [ count ]; else smalls [ numSmalls++ ] = list [ count ]; } for ( count = 0; count < numSmalls; ++count ) list [ count + low ] = smalls [ count ]; for ( count = 0; count < numBigs; ++count ) list [ count + low + numSmalls + 1 ] = bigs [ count ]; list [ low + numSmalls ] = relative; return ( low + numSmalls ); } void AuxQS ( int low, int high, int list [] ) { int pos; if ( low < high ) { pos = Partition ( low, high, list ); AuxQS ( low, pos - 1, list ); AuxQS ( pos + 1, high, list ); } return; } void QuickSort ( int list [] ) { AuxQS ( 0, MAX - 1, list ); return; }