#include<stdio.h>
int sorted(int a[],int low,int high){
int temp=0;
int sign=a[low];
while(low<high){
while(low<high && sign<a[high])
--high;
temp=a[high];
a[high]=a[low];
a[low]=temp;
while(low<high && a[low]<sign)
++low;
temp=a[low];
a[low]=a[high];
a[high]=temp;
}
return low;
}
void sort(int a[],int low,int high){
int sign=0;
if(low<high){
sign=sorted(a,low,high);
sort(a,low,sign-1);
sort(a,sign+1,high);
}
}
void main()
{
int a[20];
int i=0;
int count=0;
printf("count= ");
scanf("%d",&count);
for(i=0;i<count;i++){
printf("a[%d]=",i);
scanf("%d",&a[i]);
}
sort(a,0,count-1);
printf("/nThe sorted numbers:/n");
for(i=0;i<count;i++)
printf("%d ",a[i]);
printf("/nSort Work Is OK!/n/n");
getchar();
}
快速排序QuickSort.c
最新推荐文章于 2024-11-13 21:45:13 发布
本文介绍了一个使用C语言实现的快速排序算法。通过递归方式,该算法能够有效地对整型数组进行排序。用户可以输入任意数量的整数,程序将对其进行排序并输出排序后的结果。

2286

被折叠的 条评论
为什么被折叠?



