Pagini recente » Cod sursa (job #1339379) | Cod sursa (job #2765458) | Cod sursa (job #2396000) | Cod sursa (job #1201055) | Cod sursa (job #2614827)
#include <iostream>
#include <fstream>
#include<cstdlib>
using namespace std;
ifstream fin ("algsort.in");
ofstream fout ("algsort.out");
int a[500000];
/*void mergesort( int st, int dr )
{
if(st!=dr)
{
int mij=((st+dr)>>1);
mergesort(st,mij);
mergesort(mij+1,dr);
int k,j,cpst=st;
k=st;
j=mij+1;
while(k<=mij && j<=dr)
if(v[k]<v[j])
a[st++]=v[k++];
else
a[st++]=v[j++];
while(k<=mij)
a[st++]=v[k++];
while(j<=dr)
a[st++]=v[j++];
for(j=cpst;j<=dr;j++)
v[j]=a[j];
}
}*/
void quick_like_sonic_sort(int v[], int left, int right)
{
if(left!=right)
{
int pivot = (left+right)/2;
int b=left,e=right;
while(b<=e)
{
while(v[b]<v[pivot] && b<pivot)
b++;
while(v[e]>v[pivot] && e>pivot)
e--;
if (b<=e)
swap(v[b++], v[e--]);
}
if (e<right)
quick_like_sonic_sort(v,left,e);
if (left<b)
quick_like_sonic_sort(v,b,right);
}
}
int main()
{
int i,n;
fin >>n;
for(i=0;i<n;i++)
fin >> a[i];
quick_like_sonic_sort(a,0,n-1);
for(i=0;i<n;i++)
fout << a[i] << " ";
return 0;
}