首页 > 学院 > 开发设计 > 正文

优先队列:自定义大小比较

2019-11-08 03:17:10
字体:
来源:转载
供稿:网友
#include<queue>#include<iostream>#include<string>using namespace std;int test[100];struct cmp{ bool Operator()(int x,int y){ return test[x]>test[y]; }};struct cmp2{ bool operator()(string x,string y){ return x>y; }};struct node{ int x, y; bool operator<(const node nod){ return x>nod.x; }};int main(){ PRiority_queue<int,vector<int>,cmp> que1; priority_queue<string,vector<string>,cmp2>que2; priority_queue<node>que3; return 0;}

1.在优先队列中存储常用类型时,利用自定义结构体cmp来实现自定义的<比较。 2.在优先队列中存储自定义数据类型时,只需要在自定义类型中重载<比较。


上一篇:POJ 2506

下一篇:递归求组合

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表