Pagini recente » Cod sursa (job #2768621) | Cod sursa (job #2579749) | Cod sursa (job #2987320) | Cod sursa (job #2579744) | Cod sursa (job #3157570)
#include <bits/stdc++.h>
using namespace std;
array<int, 500'000> a;
int n;
template<typename T>
void heapSort(span<T> v) {
priority_queue<T, vector<T>, greater<>> q;
ranges::for_each(v, [&q](T &p) {
q.push(p);
});
ranges::for_each(v, [&q](T &num) {
num = q.top();
q.pop();
});
}
void read();
void print();
int main() {
read();
heapSort(span(a.data(), n));
print();
}
void print() {
ofstream out("algsort.out");
for_each(a.begin(), a.begin() + n, [&out](int x) {
out << x << ' ';
});
out << '\n';
}
void read() {
ifstream in("algsort.in");
in >> n;
for_each(a.begin(), a.begin() + n, [&in](int &x) {
in >> x;
});
}