Skip to content

Commit 1c1e503

Browse files
authored
Update 2.cpp
1 parent 33363aa commit 1c1e503

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

21/2.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
void heapSort(vector<int>& arr) {
6+
priority_queue<int> h;
7+
// 모든 원소를 차례대로 힙에 삽입
8+
for (int i = 0; i < arr.size(); i++) {
9+
h.push(-arr[i]);
10+
}
11+
// 힙에 삽입된 모든 원소를 차례대로 꺼내어 출력
12+
while (!h.empty()) {
13+
printf("%d\n", -h.top());
14+
h.pop();
15+
}
16+
}
17+
18+
int n;
19+
vector<int> arr;
20+
21+
int main() {
22+
cin >> n;
23+
for (int i = 0; i < n; i++) {
24+
int x;
25+
scanf("%d", &x);
26+
arr.push_back(x);
27+
}
28+
heapSort(arr);
29+
}

0 commit comments

Comments
 (0)