Pagini recente » Cod sursa (job #1874802) | Cod sursa (job #2839219) | Cod sursa (job #2470063) | Clasament Teme ACM Unibuc 2013 | Cod sursa (job #1047591)
#include<fstream>
# include <algorithm>
using namespace std;
ifstream f("algsort.in");
ofstream g("algsort.out");
int i,n,a[500001],j;
void qsort(int st, int dr)
{
int i,j,pivot,aux;
i=st; j=dr; pivot=a[(i+j)/2];
while(i<=j)
{
while(a[i]<pivot) i++;
while(a[j]>pivot) j--;
if (i<j)
{
aux=a[i];a[i]=a[j];
a[j]=aux;
i++; j--;
}
}
if (i<dr) qsort(i,dr);
if (j>st) qsort(st,j);
}
int main()
{
f>>n;
for(i=1;i<=n;i++) f>>a[i];
qsort(1,n);
for(i=1;i<=n;i++)
{
g<<a[i]<<" ";
}
return 0;
}