参考自:
http://baike.baidu.com/view/19016.htm?fromId=115472
#include <iostream>
using namespace std;
void quick(int a[],int left,int right){
if(left >= right)
return;
int i = left;
int j = right;
int temp;
int key = a[(left+right)/2];
while(true){
while(a[j] > key)//不能使用<=,有可能导致前半部分二次排序不起作用
j--;
while(a[i] < key)
i++;
if(i >= j)
break;
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
quick(a,left,j);//取j不取i,因为后走的i有可能超过了j
quick(a,j+1,right);
}
int main(){
int a[10];
for(int i = 0; i < 10; i++)
cin >> a[i];
quick(a,0,9);
for(int i = 0; i < 10; i++)
cout << a[i]<< " ";
cout << endl;
return 0;
}