#include <stdio.h>
int a[80];
void quickSort(int begin,int end)
{
if(begin < end)
{
int temp = a[begin]; //取第一个数为基准数
int i = begin;
int j = end;
while(i < j)
{
while(i<j && a[j] > temp)//i<j必须加
j--;
a[i] = a[j];
while(i<j && a[i] <= temp)
i++;
a[j] = a[i];
}
a[i] = temp;
quickSort(begin,i-1);//对左方的数进行递归排序
quickSort(i+1,end);//同理对右方排序
}
else
return;
}
int main()
{
int h,n;
scanf("%d",&n);
for(int h = 0; h < n; ++h){
scanf("%d", &a[h]);
}
quickSort(0,n-1);
for(int h = 0; h< n; ++h){
printf("%d", a[h]);
}
return 0;
}
快速排序
最新推荐文章于 2025-06-05 13:58:01 发布