priority_queue
![[C++] priority_queue STL 비교 구조체 comparator 사용하기](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FlyFfn%2FbtrdFnCDhfb%2FXXmuVivvysJ6tzt6dyZnRK%2Fimg.png)
[C++] priority_queue STL 비교 구조체 comparator 사용하기
algorithm STL에 있는 sort() 메서드를 사용할 때에는, 그냥 bool형 비교 메서드 하나만 만들어주면 됐었다. queue STL에 있는 priority_queue를 사용할 때에는 less()를 써서 내름차순으로 만들거나 greater()를 써서 오림차순으로 만들 수 있다. 그러나 class 형식으로 만들어서 쓰고싶을 때에는 구조체를 만들어서 그 안에 bool형 operator()(A, B)의 형태의 메서드를 만들어 주어야 한다. bool 메서드는 return true일 때 앞 뒤를 바꾼다고 생각하면 된다. 따라서 위처럼 만들 경우 p1의 시간, type에 따라 오름차순으로 정렬된다고 생각하면 된다. pq 선언은 다음처럼 해주면 된다.