#include<iostream>
using namespace std;
void print(int *l,int length)
{
for(int i = 0;i <
length;i++)
{
cout<<l[i]<<"\t";
}
cout<<"\n";
}
int
sort(int *l,int low,int high)
{
int media =
l[low];
while(low < high)
{
while(low <
high && l[high] >=
media)
high--;
l[low] =
l[high];
while(low < high && l[low] <=
media)
low++;
l[high] =
l[low];
}
l[low] = media;
return low;
}
void
partition(int *l,int low,int high)
{
int pos ;
if(low <
high)
{
pos =
sort(l,low,high);
// print(l,9);
partition(l,low,pos-1);
partition(l,pos+1,high);
}
}
int main()
{
int l[9]={8,5,7,4,6,2,3,1,9};
int size =
sizeof(l)/sizeof(int);
cout<<"排序前数组元素为:"<<endl;
print(l,size);
partition(l,0,size-1);
cout<<"排序后数组元素为:"<<endl;
print(l,size);
return
0;
}
原文:http://www.cnblogs.com/WangYinlong/p/3549108.html