这道题就是快排的变形
#include<iostream>
using namespace std;
void quickSort(int a[],int,int);
int main()
{
int array[]={34,65,12,43,67,5,78,10,3,70},k;
int len=sizeof(array)/sizeof(int);
cout<<"The orginal arrayare:"<<endl;
for(k=0;k<len;k++)
cout<<array[k]<<",";
cout<<endl;
quickSort(array,0,len-1);
cout<<"The sorted arrayare:"<<endl;
for(k=0;k<len;k++)
cout<<array[k]<<",";
cout<<endl;
system("pause");
return 0;
}
void quickSort(int s[], int l, int r)
{
if(l < r){
int p = l;
int q = r;
int key = s[l];
while (p<q) {
while(p < q && s[q] >= key){
q--;
}
if(p < q){
s[p++] = s[q];
}
while(p<q && s[p] < key){
p++;
}
if(p < q){
s[q--] = s[p];
}
}
s[p] = key;
quickSort(s,l,p-1);
quickSort(s,q+1,r);
}
}