priority_queue를 선언할 때 필요한 인자들이 있는데 다음과 같다.
priority_queue<타입, 구현체, 구조체(compare, greater, less 등)>
이때 구조체 부분에 들어가는 compare를 사용하는 방법은 아래와 같다.
다음은 우선순위큐의 pair를 first 기준으로 오름차순 하는 코드이다.
sort() 함수와는 bool 리턴값을 반대로 해주어야 한다.
struct compare{
bool operator()(pair<int, int> &l, pair<int, int> &r){
if(l.first==r.first) return l.second>r.second;
return l.first>r.first;
}
};
priority_queue<pair<int, int>, vector<pair<int, int>>, compare> pq;