void Merge(ElementType A[],ElementType Temp[],int Left,int Right,int RightEnd)
{
int temp,i, LeftEnd,count;
LeftEnd=Right-1;// 超级错误
count=RightEnd-Left+1;
temp=Left;
while(Left<=LeftEnd&& Right<=RightEnd)//超级错误
{
if(A[Left]<=A[Right])
Temp[temp++]=A[Left++];
else
Temp[temp++]=A[Right++];
}
while(Left<=LeftEnd)
Temp[temp++]=A[Left++];
while(Right<=RightEnd)
Temp[temp++]=A[Right++];
for ( i = 0; i < count; i++,RightEnd--)
A[RightEnd]=Temp[RightEnd];//超级错误
}
void (ElementType A[],ElementType Temp[],int Left,int RightEnd)
{
int center;
if(Left<RightEnd)
{
center=(Left+RightEnd)/2;
Msort(A,Temp,Left,center);
Msort(A,Temp,center+1,RightEnd);
Merge(A,Temp,Left,center+1,RightEnd);
}
}
void M_sort( ElementType A[], int N )
{ /* 归并排序 */
ElementType *TmpA;
TmpA = (ElementType *)malloc(N*sizeof(ElementType));
if ( TmpA != NULL ) {
Msort( A, TmpA, 0, N-1 );
free( TmpA );
}
else printf( "空间不足" );
}