#include<iostream>
using namespace std;
void swap( int* x, int* y)
{
int temp = *x;
*x = *y;
*y = temp;
}
int Partition( int* a, int lhs, int rhs )
{
int i,j;
i = lhs; j = lhs + 1;
while( j <= rhs )
{
if( a[j] < a[lhs] )
{
swap( &a[i+1], &a[j]);
i++;
}
j++;
}
swap( &a[lhs], &a[i]);
return i;
}
void QuickSort( int* a, int lhs, int rhs )
{
int r;
if( lhs < rhs )
{
r = Partition( a, lhs, rhs );
QuickSort( a, lhs, r-1 );
QuickSort( a, r+1, rhs );
}
}
void OutPut( int* a, int n )
{
for( int i = 0; i < n; i++ )
{
cout<< a[i]<<" ";
}
cout<<endl;
}
int main()
{
int array[7] ={11,5,8,6,3,4,2};
OutPut( array, 7);
QuickSort( array, 0, 6 );
OutPut( array, 7);
return 0;
}
转载于:https://blog.51cto.com/8734514/1625628