标签:des style blog class code java
#include <queue> #include <vector> using namespace std; priority_queue <int> maxheap; //int最大堆 struct cmp{ bool operator()(int a,int b) {return a > b;} }; priority_queue <int,vector<int>,cmp> minheap; //int最小堆
priority_queue<int, vector<int>, cmp> Q; struct cmp{ int seq; //重载运算符号 bool operator < (const Test &a) const { return seq < a.seq; // seq大的优先级高 } };
2)如果是根据与优先队列中某个元素相关的变量排序,且此变量不在结构体中,则可参考greater<int>() 的方式去重载(),具体做法如下:
priority_queue<int, vector<int>, cmp> Q; struct cmp { bool operator()(int a, int b) { // d[a]小的优先级高 return d[a] > d[b]; } };
STL--容器适配器(queue、priority_queue、stack),布布扣,bubuko.com
STL--容器适配器(queue、priority_queue、stack)
标签:des style blog class code java
原文地址:http://www.cnblogs.com/archimedes/p/cpp-adapter.html