//归并排序
#include<iostream>
using namespace std;
void merge(int a[], int left, int mid, int right, int* temp)
{
int i = left;
int j = mid + 1;
int t = 0;
while (i <= mid && j <= right)
{
if (a[i] <= a[j])
temp[t++] = a[i++];
else
temp[t++] = a[j++];
}
while (i <= mid)
temp[t++] = a[i++];
while (j <= right)
temp[t++] = a[j++];
t = 0;
while (left <= right)
a[left++] = temp[t++];
}
void sort1(int a[], int left, int right, int* temp)
{
if (left < right)
{
int mid = (left + right) / 2;
sort1(a, left, mid, temp);
sort1(a, mid + 1, right, temp);
merge(a, left, mid, right, temp);
}
}
void sort(int a[], int n)
{
int* temp = new int[10];
sort1(a, 0, n-1, temp);
}
void print(int a[], int n)
{
for (int i = 0; i < n; i++)
cout << a[i] << " ";
}
int main()
{
int a[10] = { 9,8,7,6,5,4,3,2,1,0 };
sort(a,10);
print(a,10);
}