1 #include <iostream>
2 #include <queue>
3 #include <deque>
4 #include <list>
5 using namespace std;
6
7
8 void main1()
9 {
10 //优先队列
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 //优先队列,采用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 }