#include <iostream>
using namespace std;
//参数:r表示待排序数组,s为r中第一个有序表的第一个下标,m为第一个有序表的最后一个下标;s是r中的最后一个下标
void merge( int r[],int s,int m,int t)
{
int tempr[50];
for(int k = s; k <= t; k++ )
tempr[k] = r[k];
int s1 = s;
int s2 = m+1;
int rs = s;
while(s1 <= m && s2 <= t)
if(tempr[s1]<=tempr[s2])
r[rs++] = tempr[s1++];
else
r[rs++] = tempr[s2++];
while(s1 <= m)
r[rs++] = tempr[s1++];
while(s2 <= t)
r[rs++] = tempr[s2++];
}
void MSort(int r[],int s,int t)
{
int m;
if(s==t)
;
else
{
m = (s+t)/2;
MSort(r,s,m);
MSort(r,m+1,t);
merge(r,s,m,t);
}
}
int main()
{
int r[11] = {34,45,56,2,4,6,12,3,4567,78,11};
MSort(r,0,10);
for(int i=0;i<11;i++)
cout<<r[i]<<endl;
getchar();
return 0;
}