#include <stdio.h>
int split(int *a,int low,int high)
{
int pivo,i=low,j=high,x=a[low];
while(i<j)
{
while(a[j]>x&&i<j)j--;
if(i<j)
{
a[i]=a[j];
i++;
}
while(a[i]<x&&i<j)i++;
if(i<j)
{
a[j]=a[i];
j--;
}
}
a[i]=x;
return i;
}
void quick_sort(int *a,int low,int high)
{
int i;
if(low<high)
{
i=split(a,low,high);
quick_sort(a,low,i-1);
quick_sort(a,i+1,high);
}
}
void qsort(int *a,int n)
{
quick_sort(a,0,n-1);
}
int main()
{
int i,a[10]={1,2,3,4,5,6,7,8,12,10};
qsort(a,10);
for(i=0;i<10;i++)
{
printf("%d ",a[i]);
}
return 0;
}
快速排序
最新推荐文章于 2025-01-04 00:37:43 发布
本文详细介绍了使用C语言实现的快速排序算法,包括主元选择、分区过程和递归排序,通过实例演示了如何对整数数组进行排序。
58万+

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



