Pagini recente » Cod sursa (job #1132137) | Rating sandu iuliana claudia (sanduclaudia95) | Cod sursa (job #2636080) | Cod sursa (job #1688749) | Cod sursa (job #715192)
Cod sursa(job #715192)
#include<fstream>
using namespace std;
ifstream f("algsort.in");
ofstream g("algsort.out");
int x[500001];
int partitionare(int i,int j)
{
int k=i++,aux;
while (i<=j&&x[i]<x[k]) i++;
while (i<=j&&x[j]>x[k]) j--;
if (i<j)
{aux=x[i];
x[i]=x[j];
x[j]=aux;
return partitionare(k,j);
}
else {aux=x[j];
x[j]=x[k];
x[k]=aux;
return j;}
}
void qsort(int i,int j)
{
if (i<j)
{
int k=partitionare(i,j);
qsort(i,k-1);
qsort(k+1,j);
}
}
int main()
{
int n,t;
f>>n;
for(t=1;t<=n;t++)
f>>x[t];
qsort(1,n);
for(t=1;t<=n;t++) g<<x[t]<<" ";
f.close();
g.close();
return 0;
}