Pagini recente » Cod sursa (job #113465) | Cod sursa (job #2824991) | Cod sursa (job #772532) | Cod sursa (job #2690487) | Cod sursa (job #275569)
Cod sursa(job #275569)
#include<stdio.h>
long *c,n;
void QS(long l,long r)
{
int left=l,right=r,mid=c[(left+right)>>1],aux;
do{
while(c[left]<mid)
++left;
while(c[right]>mid)
--right;
if(left<=right){
aux=c[left];
c[left]=c[right];
c[right]=aux;
++left;
--right;
}
}while(left<=right);
if(l<right)
QS(l,right);
if(left<r)
QS(left,r);
}
int main()
{
freopen("algsort.in","r",stdin);
freopen("algsort.out","w",stdout);
scanf("%ld",&n);
c=new long[n+5];
for(long i=1;i<=n;++i)
scanf("%ld",&c[i]);
QS(1,n);
for(i=1;i<=n;++i)
printf("%ld ",c[i]);
printf("\n");
return 0;
}