#include <fstream>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");
void inter(int a[50000], int s, int m, int d)
{
int i,j,k,c[50000];
i=s; j=m+1;k=1;
while(i<=m && j<=d)
if(a[i]<a[j]) c[k++]=a[i++];
else c[k++]=a[j++];
while(i<=m) c[k++]=a[i++];
while(j<=d) c[k++]=a[j++];
k=1;
for(i=s;i<=d;i++) a[i]=c[k++];
}
void msort(int a[50000], int s, int d)
{
int m;
if(s<d)
{
m=(s+d)/2;
msort(a,s,m);
msort(a,m+1,d);
inter(a,s,m,d);
}
}
void citire(int a[50000], int &n)
{
int i;
fin>>n;
for(i=1;i<=n;i++) fin>>a[i];
}
void afis(int a[50000], int n)
{
int i;
for(i=1;i<=n;i++) fout<<a[i]<<" ";
}
int main()
{
int a[50000], n;
citire(a,n);
msort(a,1,n);
afis(a,n);
return 0;
}
|