Pagini recente » Cod sursa (job #873549) | Cod sursa (job #1289609) | Cod sursa (job #1256632) | Cod sursa (job #184280) | Cod sursa (job #309742)
Cod sursa(job #309742)
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<time.h>
using namespace std;
vector <int> a;
int n,i,x;
void QSort(int st,int dr)
{
int i=st,j=dr,aux=st+rand()%(st-dr);
swap(a[st],a[aux]);
do
{
while(i<=j&&a[i]<a[aux]) i++;
while(i<=j&&a[j]>a[aux]) j--;
if(i<=j) swap(a[i++],a[j--]);
}while(i<=j);
if(i<dr) QSort(i,dr);
if(st<j) QSort(st,j);
}
inline void Cout(int x)
{
printf("%d ",x);
}
int main()
{
freopen("algsort.in","r",stdin);
freopen("algsort.out","w",stdout);
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&x);
a.push_back(x);
}
QSort(0,n-1);
for_each(a.begin(),a.end(),Cout);
printf("\n");
return 0;
}