-
1234567891011121314151617181920212223#include <bits/stdc++.h>#define endl "\n" // don't use when you cover interactive problem#define all(v) (v).begin(), (v).end()using namespace std;typedef long long ll;typedef pair<int, int> pi;typedef pair<ll, ll> pl;int main(){ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);priority_queue<int, vector<int>, greater<> > pq;pq.push(1);pq.push(2);pq.push(3);cout << pq.top() << endl; // 1이 튀어나옴return 0;}cs1234567891011121314151617181920#include <bits/stdc++.h>#define endl "\n" // don't use when you cover interactive problem#define all(v) (v).begin(), (v).end()using namespace std;typedef long long ll;typedef pair<int, int> pi;typedef pair<ll, ll> pl;int main(){ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);vector<int> v = {1, 2, 3};sort(all(v), greater<>());for(const auto& e: v) cout << e << ' '; // 3 2 1return 0;}cs
비교함수 true 일때 자리 바꿈
greater 함수가 return a > b 라서 sort 할땐 큰 수가 앞으로 나오고
priority queue에서는 부모노드와 자식노드 비교함수라 부모 노드가 크면 위치를 바꿀겁니다
그래서 작은게 올라가요(root 가 index 0)'아무거나적어~' 카테고리의 다른 글
백준 문제집 만들기 부분-자동화 (0) 2022.08.22 Markdown with LaTex (0) 2022.07.15 Colab 단축키 (0) 2022.07.06 한글 자음 모음 분리되는 문제 해결 방법 (0) 2022.06.29 [c++] Reference vs Pointer (0) 2022.06.27