#include<stdio.h>
#define M 10
#define N (M+4)/2
void main()
{ int *MERGE_SORT(int *p,int low,int high);
int i, A[M];
printf("please enter your numbers:\n");
for(i=1;i<=M;i++)
{ printf("A[%d]=",i) ;
scanf("%d",&A[i-1]);
}
MERGE_SORT(A,0,M);
printf("the arrangement result is:\n");
for(i=1;i<=M;i++)
printf("A[%d]=%d\n",i,A[i-1]);
getchar();getchar();
}
int *MERGE_SORT(int *p,int low,int high)
{int *MERGE(int *p,int low,int mid,int high);
int mid;
if(low<high)
mid=(low+high)/2;
MERGE_SORT(p,low,mid );
MERGE_SORT(p,mid+1,high);
MERGE(p,low,mid,high);
}
int *MERGE(int *p,int low,int mid,int high)
{int n1,n2,i=1,j=1,k=1;
int L[N],R[N];
n1=high-low+1;
n2=high-mid;
for(i=1;i<=n1;i++)
L[i]=p[low+i-1];
for(j=1;j<=n2;j++)
R[j]=p[mid+j];
i=1;j=1;
while(i<=n1&&j<=n2)
{if(L[i]<=R[j]){p[k-1]=L[i];i++;k++;}
else {p[k-1]=R[j];j++;k++;}
}
while(i<=n1){p[k-1]=L[i];i++;k++;}
while(j<=n2){p[k-1]=R[j];j++;k++;}
}