- 递归
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn = 100;
int a[maxn]= {0};
void merge1(int a[],int l1,int r1,int l2,int r2)
{
//两个有序数组归并
int index=0,i=l1,j=l2;
int temp[maxn]={0};
while(i<=r1&&j<=r2)
{
if(a[i]<=a[j])
temp[index++]=a[i++];
else
temp[index++]=a[j++];
}
while(i<=r1) temp[index++]=a[i++];
while(j<=r2) temp[index++]=a[j++];
for(i=0;i<index;i++)
a[l1+i]=temp[i];
}
void mergeSort(int a[],int left,int right)
{
if(left<right)
{
int mid=(left+right)/2;
mergeSort(a,left,mid);
mergeSort(a,mid+1,right);
merge1(a,left,mid,mid+1,right);
}
}
int main()
{
int t,i=0;
while(scanf("%d",&t)!=EOF)
a[i++]=t;
mergeSort(a,0,i-1);
for(int j=0;j<10;j++)
cout<<a[j]<<" ";
}