优先队列的使用方法
//优先队列:个位数大的整数优先级小 //分析:优先级 个位数大 < 个位数小 priority_queue<int,vector<int>,cmp> struct cmp{ bool operator()(const int a,const int b){ return a%>b%; } };
//效果相同,都是数字大的优先级高 priority_queue<int>; priority_queue<int,vector<int>,less<int> >;
//数字小的优先级高 priority_queue<int,vector<int>,greater<int> >;
结构体优先级设置 方法一: struct fruit { string name; int price; //价格高的优先级高 friend bool operator<(fruit f1,fruit f2) { return f1.price<f2.price; } }; 或者 struct fruit{ string name; int price; //价格低的优先级高 friend bool operator<(const fruit& f1,const fruit& f2) { return f1.price>f2.price; } };
方法二: struct fruit{ string name; int price; }; struct cmp{ //价格高的优先级高 bool operator()(fruit f1,fruit f2) { return f1.price < f2.price; } }; 或者 struct fruit{ string name; int price; }; struct cmp{ bool operator()(const fruit& f1,const fruit& f2) { return f1.price < f2.price; } };
注意!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
优先队列的本质是堆!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
相关推荐
ipqtjmqj 2020-02-24
Airuio 2020-02-11
shawsun 2019-12-15
风吹夏天 2019-11-03
生如蚁美如神 2019-10-23
lxfHaHaHa 2019-09-06
pengkingli 2019-07-01
InitJ 2019-07-01
daklqw 2019-06-30
lickylin 2019-06-28
whtqsq 2019-06-28
张小染 2019-01-10
康慧欣 2018-08-15
hanyujianke 2017-10-27
学习小殿 2017-09-21
LHpython 2019-04-22
LHpython 2019-03-05
燕返 2019-04-11