1: #include <cstdio>
2: #include <algorithm>
3: using namespace std;
4: const int maxn=10000;
5: int a[maxn],n;
6:
7: int Partition(int l,int r)
8: {
9: int key=a[l];
10: while(l<r)//结果:关键值左边小于关键值,右边反之
11: {
12: while(l<r&&a[r]>=key) r--;
13: a[l]=a[r];
14: while(l<r&&a[l]<=key) l++;
15: a[r]=a[l];
16: }
17: a[l]=key;
18: return l;
19: }
20:
21: void print()
22: {
23: int i;
24: for(i=1;i<n;i++)
25: printf("%d ",a[i]);
26: printf("%d
",a[i]);
27: }
28:
29: void Qsort(int l,int r)
30: {
31: int k;
32: if(l<r)
33: {
34: k=Partition(l,r);//k为支点
35: print();//输出当前排序情况
36: Qsort(l,k-1);//递归快排支点左边
37: Qsort(k+1,r);//递归快排支点右边
38: }
39: }
40:
41: int main()
42: {
43: int i;
44: scanf("%d",&n);
45: for(i=1;i<=n;i++)
46: scanf("%d",a+i);
47: Qsort(1,n);
48: return 0;
49: }