Pagini recente » Cod sursa (job #1016245) | Cod sursa (job #1350421) | Cod sursa (job #22471) | Cod sursa (job #2402157) | Cod sursa (job #2221186)
#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=v[(x+y)/2];
while(i<=j)
{
while(v[i]<mij)i++;
while(v[j]>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;
}