Pagini recente » Cod sursa (job #2970727) | Cod sursa (job #11699) | Cod sursa (job #1476100) | Cod sursa (job #3198000) | Cod sursa (job #2221178)
#include <fstream>
using namespace std;
ifstream f("algsort.in");
ofstream g("algsort.out");
int n,v[500001],i;
void quicksort(int x,int y)
{
int i,j,mij;
i=x;
j=y;
mij=(x+y)/2;
while(i<=j)
{
while(v[i]<v[mij])i++;
while(v[j]>v[mij])j--;
if(i<=j){swap(v[i],v[j]);
i++;
j--;}
}
if(x<j)quicksort(x,j);
if(y>i)quicksort(i,y);
}
int main()
{
f>>n;
for(i=1; i<=n; i++)f>>v[i];
quicksort(1,n);
for(i=1; i<=n; i++)g<<v[i]<<" ";
return 0;
}