priority queue

STL 2013. 8. 6. 12:54
typedef pair<int, int> ii; //자료형 정의해주고 priority_queue<int> pq1; //int형 pq 만들때 priority_queue <int, vector<int>, greater<int> > pq2; //int형 min heap priority_queue<int, vector<ii>, greater<ii> > pq3; //ii의 first를 기준으로 하는 min heap 보통 pq를 생성하면 max heap이 되기 때문에
min heap을 만드려면 위와같이 해주어야 한다, 아니면 넣을때 음수로 바꿔서 넣어도 되긴한데 그럼 헷갈릴듯
세번째 경우는, 그래프를 만들떄 edge와 cost를 pair로 짝지을때 많이 이용한다(최소경로 구할때)
ii의 first를 기준으로 정렬한다는것에 주의

'STL' 카테고리의 다른 글

compare  (0) 2013.07.12
map  (0) 2013.07.07
Posted by bogus919
,