#include <iostream>
using namespace std;
int Partition( int nArray[], int iLow, int iHigh )
{
int pivotKey = nArray[iLow];
while ( iLow < iHigh )
{
while( iLow < iHigh && nArray[iHigh] >= pivotKey )
--iHigh;
nArray[iLow] = nArray[iHigh];
while( iLow < iHigh && nArray[iLow] <= pivotKey )
++iLow;
nArray[iHigh] = nArray[iLow];
}
nArray[iLow] = pivotKey;
return iLow;
}
void QuickSort( int nArray[], int iLow, int iHigh )
{
if ( iLow >= iHigh )
{
return;
}
int nPartitionIndex = Partition( nArray, iLow, iHigh );
QuickSort( nArray, iLow, nPartitionIndex );
QuickSort( nArray, nPartitionIndex + 1, iHigh );
}
void PrintArray( int nArray[], int nCount )
{
for ( int i= 0; i < nCount; ++i )
{
cout << nArray[i] << " ";
}
cout << endl;
}
int main()
{
int nArray[20] = { 9, 12, 0, 1, 2, 34, 22, 3, 1, 2, 4, 12, 45, 0, 1, 2, 3, 54, 11, 50 };
QuickSort( nArray, 0, 19 );
PrintArray( nArray, 20 );
return 0;
}
作者:山丘儿
转载请标明出处,谢谢。原文地址:http://blog.csdn.net/s634772208/article/details/46602455