當前位置:
首頁 >
9.优先队列,priority_queue
發(fā)布時間:2025/3/20
34
豆豆
生活随笔
收集整理的這篇文章主要介紹了
9.优先队列,priority_queue
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1 #include <iostream>
2 #include <queue>
3 #include <deque>
4 #include <list>
5 using namespace std;
6
7
8 void main1()
9 {
10 //優(yōu)先隊列
11 priority_queue<int> myq;
12 myq.push(1);
13 myq.push(2);
14 myq.push(3);
15 myq.push(4);
16
17 while(!myq.empty())
18 {
19 cout << myq.top() << endl;
20 myq.pop();
21 }
22 cin.get();
23 }
24
25 struct getmoney
26 {
27 char *com;
28 int money;
29 };
30
31 struct lessX
32 {
33 bool operator()(struct getmoney &m1, struct getmoney &m2)
34 {
35 //return m1.money < m2.money;
36 if (strcmp(m1.com, m2.com) >= 0)
37 {
38 return true;
39 }
40 else
41 {
42 return false;
43 }
44 }
45 };
46
47 void main()
48 {
49 //優(yōu)先隊列,采用deque方式容易插入
50 priority_queue<getmoney, deque<getmoney>,lessX> myq;
51 getmoney getm[5] = { {"Google",30000},{"baidu",20000},{"360",15000},{"sina",10000},{"tecent",18000} };
52 for (auto i : getm)
53 {
54 myq.push(i);
55 }
56 while (!myq.empty())
57 {
58 cout << myq.top().com << " " << myq.top().money << endl;
59 myq.pop();
60 }
61 cin.get();
62 }
?
轉(zhuǎn)載于:https://www.cnblogs.com/xiaochi/p/8626698.html
與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的9.优先队列,priority_queue的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 创建性设计模式之2--建造者模式
- 下一篇: 【软件构造】第二章 软件构建的过程和工具