#include <iostream>
using namespace std;
int n;
const int N = 100000;
int q[N],temp[N];
void emerge_sort(int l,int r)
{
if (l >= r)
return;
int mid = (l + r) / 2;
emerge_sort(l, mid);
emerge_sort(mid + 1, r);
int i = l, j = mid + 1, k = 0;
while (i <= mid && j <= r)
{
if (q[i] <= q[j])
temp[k++] = q[i++];
else
temp[k++] = q[j++];
}
while (i <= mid)
temp[k++] = q[i++];
while (j <= r)
temp[k++] = q[j++];
for (i = l, j = 0; i <= r; i++, j++)
q[i] = temp[j];
return;
}
int main()
{
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> q[i];
}
emerge_sort(0, n - 1);
for (int i = 0; i < n; i++)
{
cout << q[i];
cout << " ";
}
return 0;
}
将递归后的结果统合起来,注意i是等于l而不是1