Pagini recente » Cod sursa (job #133889) | Cod sursa (job #1284476) | Cod sursa (job #1138189) | Cod sursa (job #1557536) | Cod sursa (job #1624040)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin ("algsort.in");
ofstream fout ("algsort.out");
const int nmax = 500005;
int v[nmax];
void quicksort(int st, int dr)
{
int i=st, j=dr, pivot=(st+dr)>>1;
while(i<=j)
{
while(v[i] < v[pivot]) i++;
while(v[j] > v[pivot]) j--;
if(i<=j)
{
swap(v[i], v[j]);
i++;
j--;
}
}
if(st < j) quicksort(st, j);
if(i < dr) quicksort(i, dr);
}
int main()
{
ios_base::sync_with_stdio(false);
int n, i;
fin >> n;
for(i=1; i<=n; i++)
fin >> v[i];
quicksort(1, n);
for(i=1; i<=n; i++)
fout << v[i] << " ";
fin.close();
fout.close();
return 0;
}