哈哈,看来那三个小时没白费,这道纯粹的排序题,几分钟就搞定了,吃饭去
#include<stdio.h>
int partsort(int a[],int low,int high)
{
int key;
key=a[low];
while(low<high)
{
while(low<high&&a[high]>=key)
high--;
if(low<high)
a[low++]=a[high];
while(low<high&&a[low]<=key)
low++;
if(low<high)
a[high--]=a[low];
}
a[low]=key;
return low;
}
void quicksort(int a[],int s,int t)
{
int loc;
if(s<t)
{
loc=partsort(a,s,t);
quicksort(a,s,loc-1);
quicksort(a,loc+1,t);
}
}
int main()
{
int t,n,i,a[1002];
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
quicksort(a,1,n);
for(i=1;i<=n-1;i++)
printf("%d ",a[i]);
printf("%d\n",a[n]);
}
return 0;
}