#include <iostream>
#include <queue>
#include <string>
using namespace std;
struct Fruit
{
string Name;
int Price;
//设置价格高的 优先级高
friend bool operator < (Fruit &f1, Fruit &f2)
{
return f1.Price < f2.Price;
}
}f1,f2,f3,f4;
struct Game
{
string Name;
int Price;
}g1,g2,g3;
struct Cmp
{
//设置价格低的优先级高
bool operator () (Game &g1, Game &g2)
{
return g1.Price > g2.Price;
}
};
int main(void)
{
priority_queue<Game,vector<Game>,Cmp>game;
g1.Name = "守望先锋";
g1.Price = 20;
g2.Name = "LOL";
g2.Price = 0;
g3.Name = "PUBG";
g3.Price = 98;
game.push(g1);
game.push(g2);
game.push(g3);
cout<<game.top().Name<<game.top().Price<<endl;
return 0;
}
/*int main(int argc, char** argv)
{
priority_queue<Fruit>fruit;
f1.Name = "桃子";
f1.Price = 10;
f2.Name = "西瓜";
f2.Price = 20;
f3.Name = "樱桃";
f3.Price = 5;
f4.Name = "荔枝";
f4.Price = 100;
fruit.push(f1);
fruit.push(f2);
fruit.push(f3);
fruit.push(f4);
cout<<fruit.top().Name<<fruit.top().Price<<endl;
return 0;
}*/
priority_queue的优先级设置
最新推荐文章于 2024-08-18 19:23:29 发布
2564

被折叠的 条评论
为什么被折叠?



