Pagini recente » Cod sursa (job #125222) | Cod sursa (job #2312359) | Cod sursa (job #189017) | Cod sursa (job #1044903) | Cod sursa (job #251611)
Cod sursa(job #251611)
#include <stdio.h>
int n,v[500500];
void qsort(int a,int b)
{
int i=a,j=b,tmp,x=v[(a+b)/2];
do
{
while(v[i]<x) ++i;
while(v[j]>x) --j;
if(i<=j)
{
tmp=v[i];
v[i]=v[j];
v[j]=tmp;
++i;
--j;
}
}
while(i<=j);
if(a<j) qsort(a,j);
if(i<b) qsort(i,b);
}
int main()
{
int i;
freopen("algsort.in","r",stdin);
freopen("algsort.out","w",stdout);
scanf("%d",&n);
for(i=1;i<=n;++i)
scanf("%d",&v[i]);
qsort(1,n);
for(i=1;i<=n;++i)
printf("%d ",v[i]);
return 0;
}