-
頭文件
#include <queue> -
自定義比較函數(shù)
- lambda (c++11)
注意使用關鍵字decltypeauto comp = [origin]( Point a, Point b ) { auto aDis = distanceSquare(a, origin); auto bDis = distanceSquare(b, origin); if (aDis == bDis) { if (a.x == b.x) { return a.y < b.y; } else { return a.x < b.x; } } else { return aDis < bDis; } }; priority_queue<Point, vector<Point>, decltype(comp)> q(comp); - 結構體 TBD
struct cmp{ bool operator() ( Point a, Point b ){ if( a.x== b.x ) return a.y> b.y; return a.x> b.x; } }; priority_queue<Point, vector<Point>, cmp> q(); - 重載操作符
struct node { friend bool operator< (node n1, node n2) { return n1.priority < n2.priority; } int priority; int value; };
- lambda (c++11)
排列順序
使用<時大的內(nèi)容具有較高優(yōu)先級
Reference
http://blog.csdn.net/yuanjilai/article/details/8043157
https://stackoverflow.com/questions/5807735/c-priority-queue-with-lambda-comparator-error