标签:node pre priority clu nod log span 介绍 logs
三个参数:priority_queue<Type,Container, Functional>
①Type:数据类型②:Container:容器(默认是vector)③Functional:元素比较方式
按升序排序 ( 按降序排序则把第三个参数改为less<int> ) :
#include <iostream> #include <queue> using namespace std; int main(int argc, const char * argv[]) { priority_queue<int,vector<int>,greater<int> >q; for(int i=0;i<5;i++){ q.push(i); } while(!q.empty()){ cout<<q.top()<<endl; q.pop(); } return 0; }
#include <iostream> #include <queue> using namespace std; struct Node{ int x; int y; }node; struct cmp{ bool operator()(Node a,Node b){ if(a.x==b.x)return a.y<b.y; return a.x<b.x; } }; int main(int argc, const char * argv[]) { priority_queue<Node,vector<Node>,cmp >q; for(int i=0;i<5;i++){ node.x=i; node.y=i+1; q.push(node); } while(!q.empty()){ cout<<q.top().x<<‘ ‘<<q.top().y<<endl; q.pop(); } return 0; }
标签:node pre priority clu nod log span 介绍 logs
原文地址:http://www.cnblogs.com/LuRenJiang/p/7168215.html