Pagini recente » Cod sursa (job #207472) | Cod sursa (job #1038009) | Cod sursa (job #164618) | Cod sursa (job #332924) | Cod sursa (job #1937609)
#include <iostream>
#include <fstream>
#define maxN 500005
using namespace std;
ifstream fin("algsort.in");
ofstream fout("algsort.out");
int n,v[maxN];
inline void swap(int &a, int &b)
{
int temp;
temp=a; a=b; b=temp;
}
inline void quickSort(int v[], int n, int l, int r)
{
if (l>=r) return;
int i=l, j=r, pivot=v[(i+j)/2];
while (i<j)
{
while (v[i]<pivot) ++i;
while (v[j]>pivot) --j;
if (i<j)
{
swap(v[i],v[j]);
++i;
--j;
}
}
quickSort(v,n,l,i-1);
quickSort(v,n,i+1,r);
}
int main()
{
fin>>n;
for (int i=1; i<=n; ++i)
fin>>v[i];
quickSort(v,n,1,n);
for (int i=1; i<=n; ++i)
fout<<v[i]<<' ';
return 0;
}