#include<stdio.h>
#define maxsize 100
void quick(int *a,int low,int high)
{
int l=low,r=high;
a[0]=a[low];
while(low<high)
{
while(low<high&&a[0]<=a[high])
{
high--;
}
if(low<high)
{
a[low]=a[high];
}
while(low<high&&a[0]>=a[low])
{
low++;
}
if(low<high)
{
a[high]=a[low];
}
}
a[low]=a[0];
if(l<low-1)
quick(a,l,low-1);
if(low+1<r)
quick(a,low+1,r);
return;
}
int main()
{
int a[maxsize];
int n;
int i;
scanf("%d",&n);
for(i=1; i<=n; i++)
{
scanf("%d",&a[i]);
}
quick(a,1,n);
for(i=1; i<=n; i++)
{
printf("%d",a[i]);
}
return 0;
}
c语言快速排序
最新推荐文章于 2024-08-31 18:18:12 发布