#include<iostream> using namespace std; const int maxn = 100005; int tmp[maxn]; void mergesort(int a[],int l,int r){ if(l >= r ) return ;//1wei不需要排 int mid =l + r >>1;//取中间值 mergesort(a,l,mid);//左分区 mergesort(a,mid+1,r);//右分区 int k = 0, i = l, j = mid + 1;//i和j 做两个指针 左右分区同时比较,小值插入到数组tmp中 while(i <= mid && j<=r){ if(a[i] < a[j]) tmp[k++] = a[i++]; else tmp[k++] = a[j++]; } while(i <= mid) tmp[k++] = a[i++];//处理左分区剩余数据,依次插入tmp while(j <= r) tmp[k++] = a[j++];//处理右分区剩余数据,依次插入tmp for(int i = l,j = 0;i<=r;i++,j++){ a[i] = tmp[j];//a依次接收temp数组中的值,存回a数组 } } int main(){ int n; cin>>n; int *a = new int[n]; for(int i =0 ;i<n;i++){ cin>>a[i]; } mergesort(a,0,n-1); for(int i =0;i< n ;i++) { cout<<a[i]; } return 0; }