#include<iostream>
#include<cstdio>
#include<malloc.h>
using namespace std;
void disp(int a[],int n){
for(int i=0;i<n;i++){
cout<<a[i]<<" ";
}
printf("\n");
}
void merge(int a[],int low,int mid,int high){
int *temp;
int i=low,j=mid+1,k=0;
temp = (int*)malloc(sizeof(int)*(high-low+1));
while(i<=mid&&j<=high){
if(a[i]<=a[j]){
temp[k]=a[i];
i++;k++;
}
else{
temp[k]=a[j];
j++;k++;
}
}
while(i<=mid){
temp[k]=a[i];
i++;k++;
}
while(j<=high){
temp[k]=a[j];
j++;k++;
}
for(k=0,i=low;i<=high;k++,i++)
a[i]=temp[k];
free(temp);
}
void Mergesort(int a[],int low,int high){
int mid;
if(low<high){
mid=(low+high)/2;
Mergesort(a,low,mid);
Mergesort(a,mid+1,high);
merge(a,low,mid,high);
}
}
int main(){
int n=10;
int a[]={51,12,23,68,92,45,76,80,30,63};
printf("排序前的数组为:");
disp(a,n);
Mergesort(a,0,n);
printf("排序后的数组为:");
disp(a,n);
}