Cod sursa(job #346684)
| Utilizator | Data | 9 septembrie 2009 07:26:58 | |
|---|---|---|---|
| Problema | Sortare prin comparare | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include<stdio.h>
int v[500010],N;
inline void qsort(int lf,int rh)
{
int aux,st=lf,dr=rh,piv=v[(st+dr)/2];
while(st<dr)
{
while(v[st]<piv) ++st;
while(v[dr]>piv) --dr;
if(st<=dr)
{
aux=v[st];
v[st]=v[dr];
v[dr]=aux;
++st;
--dr;
}
}
if(lf<dr)
qsort(lf,dr);
if(st<rh)
qsort(st,rh);
}
int main()
{
freopen("algsort.in","r",stdin);
freopen("algsort.out","w",stdout);
scanf("%d",&N);
for(int i=1;i<=N;++i)
scanf("%d",&v[i]);
qsort(1,N);
for(int i=1;i<=N;++i)
printf("%d ",v[i]);
}
