Pagini recente » Cod sursa (job #2733517) | Cod sursa (job #2731769) | Cod sursa (job #868658) | Cod sursa (job #2883065) | Cod sursa (job #874629)
Cod sursa(job #874629)
#include<fstream>
#define nmax 10000
using namespace std;
ifstream f("algsort.in");
ofstream g("algsort.out");
int n,l,r,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;
}