#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 50
int main()
{
int i;
int a[SIZE];
srand((unsigned int)time(NULL));
for(i = 0;i < SIZE;i++)
{
a[i] = rand()%100;
printf("a[%d] = %d\t",i,a[i]);
}
sort(a,0,SIZE);
for(i = 0;i < SIZE;i ++)
printf("paixuhou : a[%d] = %d\n",i,a[i]);
return 0;
}
void sort(int a[], int l,int r)
{
if(l < r)
{
int i,j,x;
i = l;
j = r;
x = a[i];
while(i < j)
{
while(i < j && a[j] > x)
j--;
if(i < j)
{
a[i] = a[j];
i++;
}
while(i < j && a[i] < x)
{
i++;
}
if(i < j)
{
a[j] = a[i];
j--;
}
}
a[i] = x;
sort(a,l,i-1);
sort(a,i+1,r);
}
}
快速排序
最新推荐文章于 2021-07-24 23:27:25 发布