分治法排序
#include “stdio.h”
int fun1(int *n,int x,int y)
{
int le = y;
if(x == y)return 0;
while(x != y)
{
while(y>x)
{
if(n[x] > n[y])
{
n[x] = n[x] + n[y];
n[y] = n[x] - n[y];
n[x] = n[x] - n[y];
x++;
break;
}
y–;
}
while(x<y)
{
if(n[x] > n[y])
{
n[x] = n[x] + n[y];
n[y] = n[x] - n[y];
n[x] = n[x] - n[y];
y–;
break;
}
x++;
}
}
int m=x;
if(m-0>0)fun1(n,0,m-1);
if(le-m-1 >0) fun1(n,m+1,le);
}
int main()
{
int array[]={5,2,1};
int len;
len = sizeof(array) / sizeof(int);
fun1(array,0,len-1);
int i;
for(i=0;i<len;i++)
{
printf("%d “,array[i]);
}
printf(”\n");
}