Pagini recente » Cod sursa (job #3162345) | Cod sursa (job #1246895) | Cod sursa (job #478952) | Cod sursa (job #3200429) | Cod sursa (job #1953360)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("algsort.in");
ofstream fout ("algsort.out");
const int maxn = 5e5 + 5;
int V[maxn];
void QuickSort (int left, int right) {
int i = left;
int j = right;
int pivot = V[(left + right) >> 1];
while (i <= j) {
while (V[i] < pivot) i++;
while (V[j] > pivot) j--;
if (i <= j) {
swap(V[i], V[j]);
i++;
j--;
}
}
if (left < j) QuickSort(left, j);
if (i < right) QuickSort(i, right);
}
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] << " ";
}
fout << "\n";
fin.close();
fout.close();
return 0;
}