#include <iostream> #include <queue> //for more tutorials 上 C, C ++, STL, DS visit www.ProDeveloperTutorial.com using namespace std; int main () { std::priority_queue<int> mypq; mypq.push (1); mypq.push (2); mypq.push (3); mypq.push (4); cout<<"Size of mypq is "<< mypq.size()<<endl; cout<<"mypq elements are: "<<endl; while (!mypq.empty()) { std::cout << ' ' << mypq.top(); mypq.pop(); } return 0; }
在本章中,我们将学习:
1. priority_queue简介。
2. priority_queue操作。
3. priority_queue成员声明。
4. priority_queue成员函数
1. priority_queue简介。
1. priority_queue是一种容器适配器。
2.它支持FIFO [先进先出]。
3. FIFO意味着,首先插入的元素将首先被移除。
以下是要用于堆栈的头文件:
#include <queue> // std::stack
2. priority_queue操作。
priority_queue将支持以下操作:
空的
尺寸
面前
背部
推回
流行音乐_front
3. priority_queue成员声明。
std::priority_queue<int> mypriority_queue; mypriority_queue.push (1); mypriority_queue.push (2); mypriority_queue.push (3); mypriority_queue.push (4);
4. priority_queue成员函数
空的 :它将测试容器是否为空
尺寸 :将返回大小
推 :将插入元素
流行音乐 :它将删除元素
最佳 :它将访问顶部元素
#include <iostream> #include <queue> //for more tutorials 上 C, C ++, STL, DS visit www.ProDeveloperTutorial.com using namespace std; int main () { std::priority_queue<int> mypq; mypq.push (1); mypq.push (2); mypq.push (3); mypq.push (4); cout<<"Size of mypq is "<< mypq.size()<<endl; cout<<"mypq elements are: "<<endl; while (!mypq.empty()) { std::cout << ' ' << mypq.top(); mypq.pop(); } return 0; }
输出:
Size of mypq is 4 mypq elements are: 4 3 2 1
该网站上可用的教程列表:
C编程20+章 | C ++编程80+章 |
100多个编码问题 | 数据结构和算法85+章 |
系统设计20+章 | Shell脚本编写12章 |
4g LTE 60+章节 | 最常见的编码问题 |
5G NR 50+章 | Linux系统编程20+章 |