Pagini recente » Cod sursa (job #738450) | Cod sursa (job #2347651) | Cod sursa (job #1172554) | Cod sursa (job #3265120) | Cod sursa (job #2898342)
#include <bits/stdc++.h>
using namespace std;
ifstream in("algsort.in");
ofstream out("algsort.out");
void QuickSortcresc(vector<int> &v, int st, int dr) {
if (st < dr) {
int mij = (st + dr) / 2;
int aux = v[st];
v[st] = v[mij];
v[mij] = aux;
int i = st, j = dr, d = 0;
while (i < j) {
if (v[i] > v[j]) {
aux = v[i];
v[i] = v[j];
v[j] = aux;
d = 1 - d;
}
i += d;
j -= 1 - d;
}
QuickSortcresc(v, st, i);
QuickSortcresc(v, i + 1, dr);
}
}
int v[1000001];
int main() {
int n, mij, x;
vector<int> v;
in >> n;
if (n % 2 == 0) {
mij = n / 2;
} else {
mij = (n + 1) / 2;
}
for (int i = 0; i < n; ++i) {
in >> x;
v.push_back(x);
}
QuickSortcresc(v, 0, v.size() - 1);
for (int i = 0; i < v.size(); ++i) {
out << v[i] << " ";
}
in.close();
out.close();
return 0;
}