Pagini recente » Cod sursa (job #2755774) | lista-lui-wefgef/clasament | Cod sursa (job #2755319) | Cod sursa (job #2789286) | Cod sursa (job #1579750)
#include <iostream>
#include <fstream>
using namespace std;
#define NMAX 500005
int N, A[NMAX];
ifstream fin("algsort.in");
ofstream fout("algsort.out");
void QuickSort(int A[], int l, int r)
{
int x = A[(l + r) / 2];
int i = l, j = r;
while (i <= j)
{
while (A[i] < x) ++i;
while (A[j] > x) --j;
if (i <= j)
{
int aux = A[i];
A[i] = A[j];
A[j] = aux;
++i;
--j;
}
}
if (l < j) QuickSort(A, l, j);
if (i < r) QuickSort(A, i, r);
}
int main()
{
fin >> N;
for (int i = 1; i <= N; ++i)
fin >> A[i];
QuickSort(A, 1, N);
for (int i = 1; i <= N; ++i)
fout << A[i] << ' ';
return 0;
}