Pagini recente » Cod sursa (job #2561874) | Clasament cerculetz_02 | Cod sursa (job #2382836) | Cod sursa (job #1052285) | Cod sursa (job #472495)
Cod sursa(job #472495)
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#define N 10000
int mat[N];
void sort(int st,int dr)
{int s=st,d=dr,aux,offset=rand()%(dr-st+1),p=mat[st+offset];
while(s<d)
{while(mat[s]<p)s++;
while(mat[d]>=p)d--;
if(s<d)
{aux=mat[s];
mat[s]=mat[d];
mat[d]=aux;
s++;
d--;
}
}
if(st<d)
sort(st,d);
if(s<dr)
sort(s,dr);
}
int main ()
{freopen("sort.in","r",stdin);
freopen("sort.out","w",stdout);
int n,i;
scanf("%d",&n);
for (i=1;i<=n;i++)
{scanf("%d",&mat[i]);
}
srand(time(NULL));
sort(1,n);
for (i=1;i<=n;i++)
{printf("%d",mat[i]);
}
return 0;
}