#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define N 8
void kuaisu(int *a, int n);
void quick(int *a, int left, int right);
int main()
{
//int i, arr[]={13,19,9,5,12,8,7,4,11,2,6,21};
int i, arr[]={13,19,9,5,12,8,7,21};
printf("\n原数据序列:\n");
for(i=0;i<N;i++)
{
printf("%d ",arr[i]);
}
printf("\n*************************\n");
kuaisu(arr,N);
printf("\n排序后数据序列:\n");
for(i=0;i<N;i++)
{
printf("%d ",arr[i]);
}
printf("\n");
system("pause");
return 0;
}
void kuaisu(int *a,int n)
{
quick(a,0,n-1);
}
void quick(int*a, int left, int right)
{
int f, l, r, s,t;
l=left;
r=right;
s=(left+right)/2;
f=a[(left+right)/2];
while(l<r)
{
while(a[l]<f)
++l;
while(a[r]>f)
--r;
if(l<=r)
{t=a[l];
a[l]=a[r];
a[r]=t;
++l;
--r;
}
}
if(l==r)
l++;
if(left<r)
quick(a,left,l-1);
if(l<right)
quick(a,r+1,right);
}