Pagini recente » Cod sursa (job #813747) | Cod sursa (job #2863809) | Cod sursa (job #1143283) | Cod sursa (job #1866636) | Cod sursa (job #3254624)
#include <fstream>
using namespace std;
ifstream cin("algsort.in");
ofstream cout("algsort.out");
int n,v[500001],a[500001];
void merge_sort(int st,int dr){
if(st>=dr)
return ;
int mid=(st+dr)/2;
merge_sort(st,mid);
merge_sort(mid+1,dr);
int i=st,j=mid+1,k=st;
while(i<=mid&&j<=dr)
if(v[i]<=v[j])
a[k++]=v[i++];
else
a[k++]=v[j++];
while(i<=mid)
a[k++]=v[i++];
while(j<=dr)
a[k++]=v[j++];
for(int i=st;i<=dr;i++)
v[i]=a[i];
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>v[i];
merge_sort(1,n);
for(int i=1;i<=n;i++)
cout<<v[i]<<" ";
return 0;
}