MCPcopy Create free account
hub / github.com/EricPengShuai/Interview / main

Function main

STL/priority_queue.cpp:5–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3
4using namespace std;
5int main()
6{
7 // 默认是大顶堆,priority_queue<int, vector<int>, less<int> > a
8 priority_queue<int> a;
9
10 // 小顶堆
11 priority_queue<int, vector<int>, greater<int> > c;
12 priority_queue<string> b;
13
14 // 插入元素
15 for (int i = 0; i < 5; ++ i) {
16 a.push(i);
17 c.push(i);
18 }
19
20 // 打印元素,注意优先顺序
21 while(!a.empty()) {
22 cout << a.top() << ' ';
23 a.pop();
24 }
25 cout << endl;
26
27 while(!c.empty()) {
28 cout << c.top() << ' ';
29 c.pop();
30 }
31 cout << endl;
32
33 b.push("abc");
34 b.push("abcd");
35 b.push("cbd");
36 b.emplace("aaa");
37 while(!b.empty()) {
38 cout << b.top() << ' ';
39 b.pop();
40 }
41 cout << endl;
42 return 0;
43}
44/*
45优先队列具有队列的所有特性,包括队列的基本操作,只是在这基础上添加了内部的一个排序,它本质是一个堆实现的。
46

Callers

nothing calls this directly

Calls 4

pushMethod · 0.45
emptyMethod · 0.45
topMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected