Pagini recente » Istoria paginii utilizator/cirjontuionela15 | Cod sursa (job #332574) | Profil M@2Te4i | Profil M@2Te4i | Cod sursa (job #1985576)
#include <iostream>
#include <fstream>
using namespace std;
const int nMax = 500005;
int n;
int v[nMax];
void citire()
{
ifstream in("algsort.in");
in >> n;
for(int i = 1; i <= n; ++i)
in >> v[i];
in.close();
}
void quick_sort(int st, int dr)
{
int pivot = v[(st + dr) / 2];
int i = st, j = dr;
while(i <= j)
{
while(v[i] < pivot)
++i;
while(v[j] > pivot)
--j;
if(i <= j)
{
swap(v[i], v[j]);
++i;
--j;
}
}
if(st < j)
quick_sort(st, j);
if(i < dr)
quick_sort(i, dr);
}
void afisare()
{
ofstream out("algsort.out");
for(int i = 1; i <= n; ++i)
out << v[i] << " ";
out.close();
}
int main()
{
citire();
quick_sort(1, n);
afisare();
return 0;
}