求c语言快排程序

来源:百度知道 编辑:UC知道 时间:2024/06/15 12:25:00
不要随机算法,谢谢各位大哥大姐啦!!

#include<stdio.h>

int a[10]={4,7,2,9,1,3,8,5,0,6};
int partition(int p,int r)
{
int t,i,j,x;
i=p,j=r+1,x=a[p];
while(1)
{
while(a[++i]<x);
while(a[--j]>x);
if(i>=j)break;
t=a[i];
a[i]=a[j];
a[j]=t;
}
a[p]=a[j];
a[j]=x;
return j;
}

void qSort(int p,int r)
{
int q;
if(p<r)
{
q=partition(p,r);
qSort(p,q-1);
qSort(q+1,r);
}
}

void main()
{
qSort(0,9);
int i;
for(i=0;i<10;i++)
printf("%d ",a[i]);
}

VS2008下编译通过.

#include <stdio.h>
void quicksort(int data[], int low, int high)
{
int i, pivotkey, j;
if (low < high)
{
pivotkey = data[low];
i = low;
j = high;
while (i < j)
{
while (i < j && data[j] >