Pagini recente » Cod sursa (job #1010490) | Cod sursa (job #1515964) | Cod sursa (job #1312239) | Cod sursa (job #2611991) | Cod sursa (job #1723543)
#include <bits/stdc++.h>
using namespace std;
ifstream f("algsort.in");
ofstream g("algsort.out");
int n, a[500050];
void QS(int st,int dr)
{
int piv;
int i = st;
int j = dr;
piv = a[(i + j) / 2];
while(i <= j)
{
while(i < dr && a[i] < piv) i++;
while(j > st && a[j] > piv) j--;
if(i <= j)
{
swap(a[i], a[j]);
i++;
j--;
}
}
if (st < j) QS(st, j);
if (i < dr) QS(i, dr);
}
int main()
{
f >> n;
for(int i = 1; i <= n; i++)
f >> a[i];
f.close();
QS(1, n);
for(int i = 1; i <= n; i++)
g << a[i] << " ";
g << "\n";
g.close();
return 0;
}