#include<;
#define LEN 8
int a[LEN]={5,2,4,7,1,3,2,6};
int tempa[LEN];
void merge(int a[],int tempa[],int left,int right,int rightend)
{
int i,temp;
int leftend=right-1;
int num=rightend-left+1;
temp=left;
while(left<=leftend&&right<=rightend)
{
if(a[left]<a[right])
{
tempa[temp++]=a[left++];
}
else
{
tempa[temp++]=a[right++];
}
}
while(left<=leftend)
{
tempa[temp++]=a[left++];
}
while(right<=rightend)
{
tempa[temp++]=a[right++];
}
for(i=0;i<num;i++,rightend--)
{
a[rightend]=tempa[rightend];
}
}
void sort(int a[],int tempa[],int left,int right)
{
int mid;
if(left<right)
{
mid=(left+right)/2;
sort(a,tempa,left,mid);
sort(a,tempa,mid+1,right);
merge(a,tempa,left,mid+1,right);
}
}
int main()
{
sort(a,tempa,0,7);
for(int i=0;i<LEN;++i)
{
printf("%d,",a[i]);
}
return 0;
}
本人是编程小白,程序如果有问题,求教各位大神指出