//统一函数接口 void Merge_Sort(int *A,int n) { int length=1; int i; int *TmpA=(int *)malloc(n*sizeof(int)); if(TmpA!=NULL) { while(length<n) { Merge_Pass(A,TmpA,n,length);//有序数列存入TmpA length*=2; // for(i=0;i<M;i++) // { // printf("%d ",A[i]); // } // printf("\n"); Merge_Pass(TmpA,A,n,length);//将有序数列TmpA导入A length*=2; } free(TmpA); } else { printf("No extra space"); } }
void Merge_Sort(int a[],int size) { int *temp = a; int seg = 1; while(seg<size) { Merge_Pass(a,temp,seg,size); seg += seg; Merge_Pass(temp,a,seg,size); seg += seg; } }