Pagini recente » Cod sursa (job #1549055) | Cod sursa (job #2734226) | Cod sursa (job #2733636) | Cod sursa (job #2735404) | Cod sursa (job #874630)
Cod sursa(job #874630)
#include<fstream>
#define nmax 500002
using namespace std;
ifstream f("algsort.in");
ofstream g("algsort.out");
int n,v[nmax];
void quicksort(int v[], int l, int r)
{
int i=l,j=r;
int piv=v[(l+r)/2];
while(i<=j){
while(v[i]<piv) i++;
while(v[j]>piv) j--;
if(i<=j){
int aux=v[i];
v[i]=v[j];
v[j]=aux;
i++;
j--;
}
}
if(i<r) quicksort(v,i,r);
if(l<j) quicksort(v,l,j);
}
int main()
{
f>>n;
int i;
for(i=1;i<=n;i++) f>>v[i];
quicksort(v,1,n);
for(i=1;i<=n;i++) g<<v[i]<<" ";
f.close();g.close();
return 0;
}