forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.cpp
More file actions
29 lines (25 loc) · 598 Bytes
/
2.cpp
File metadata and controls
29 lines (25 loc) · 598 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <bits/stdc++.h>
using namespace std;
void heapSort(vector<int>& arr) {
priority_queue<int> h;
// 모든 원소를 차례대로 힙에 삽입
for (int i = 0; i < arr.size(); i++) {
h.push(-arr[i]);
}
// 힙에 삽입된 모든 원소를 차례대로 꺼내어 출력
while (!h.empty()) {
printf("%d\n", -h.top());
h.pop();
}
}
int n;
vector<int> arr;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
arr.push_back(x);
}
heapSort(arr);
}