Pagini recente » Cod sursa (job #637414) | Cod sursa (job #1122624) | Cod sursa (job #2296406) | Cod sursa (job #3298023) | Cod sursa (job #647456)
Cod sursa(job #647456)
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int MAX_N = 500001 ;
int n;
int v[MAX_N];
void QUICKSORT(int st,int dr)
{
if(st<dr)
{
int dif = dr-st +1 ;
int pivot = rand()%dif + st ;
swap(v[pivot],v[dr]);
int indice = st-1;
for(int i=st;i<=dr;++i)
{
if(v[i]<=v[dr])
{
++indice;
swap(v[indice],v[i]);
}
}
QUICKSORT(st,indice-1);
QUICKSORT(indice+1,dr);
}
}
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]);
QUICKSORT(1,n);
for(int i=1;i<=n;++i)
printf("%d ",v[i]);
printf("\n");
return 0;
}