STL之优先级队列priority_queue
摘要:
priority_queue,自适应容器(即容器适配器):不能由list来组建;
最大值优先级队列(最大值始终在对首,push进去时候)
最小值优先级队列;
优先级队列适配器 STL priority_queue
priority_queue<int, deque<int> > pg;
priority_queue<int, vector<int> > pg;
STL中实现的方法:
pg.empty();
pg.size();
pg.top(); //查看队首的元素
pg.pop(); //从队首删除元素;
pg.push(item); //从队尾加入元素
#include <iostream>
#include <queue> using namespace std;
int main()
{
//最大值有限队列, 会进行自动排序
priority_queue<int, vector<int> > pg;
priority_queue<int, deque<int> > pg2;
//priority_queue<int> pg3; pg.push();
pg.push();
pg.push(-);
pg.push(); std::cout <<"priority_queue first item: " << pg.top() << std::endl;
while(!pg.empty()){
std::cout<<"priority_queue del item: " << pg.top() << std::endl;
pg.pop();
}
//最小值有限队列,从小到大排序
priority_queue<int, deque<int>, greater<int> > pg3;
pg3.push();
pg3.push();
pg3.push(-);
pg3.push();
std::cout <<"priority_queue first item: " << pg3.top() << std::endl;
while(!pg3.empty()){
std::cout<<"priority_queue del item: " << pg3.top() << std::endl;
pg3.pop();
} return ;
}
STL之优先级队列priority_queue的更多相关文章
- STL学习系列七:优先级队列priority_queue容器
1.简介 最大值优先级队列.最小值优先级队列 优先级队列适配器 STL priority_queue 用来开发一些特殊的应用,请对stl的类库,多做扩展性学习 这里给个例子: #include< ...
- C++ STL 学习笔记__(6)优先级队列priority_queue基本操作
10.2.7优先级队列priority_queue v 最大值优先级队列.最小值优先级队列 v 优先级队列适配器 STL priority_queue v 用来开发一些特殊的应用,请对stl的类 ...
- stl的优先级队列
#include <iostream> #include <vector> #include <queue> using namespace std; class ...
- C++ - 库函数优先级队列(priority_queue)输出最小值 代码
库函数优先级队列(priority_queue)输出最小值 代码 本文地址: http://blog.csdn.net/caroline_wendy 库函数优先级队列(priority_queue)的 ...
- c++ 优先级队列(priority_queue)
从网上搜优先级队列用法,都是有些乱七八糟的,有几种用法都没说,直接贴代码.实在郁闷,于是自己在此归纳归纳. 废话不多说,直入主题. 优先级队列的核心是比较函数的实现. 比较函数有两种实现方法: 1.在 ...
- STL中的优先级队列priority_queue
priority_queue(queue类似)完全以底部容器为根据,再加上二叉堆(大根堆或者小根堆)的实现原理,所以其实现非常简单,缺省情况下priority_queue以vector作为底部容器.另 ...
- STL中的优先级队列(priority_queue)的自己实现priqueue
这篇文章主要介绍堆(最大堆和最小堆),以及一些系统对一些任务,比如线程,进程做调度的时候,所采用的优先级队列. 主要思想就是,做一个最大堆(任务的权重最大的在顶端),把顶端的任务取出,重新做一个堆,处 ...
- 优先级队列Priority_queue
定义 拥有权值观点的queue,,一个是返回最高优先级对象,一个是在底端添加新的对象.这种数据结构就是优先级队列(Priority Queue) . 实现 利用max_heap完成,以vector表现 ...
- STL之heap与优先级队列Priority Queue详解
一.heap heap并不属于STL容器组件,它分为 max heap 和min heap,在缺省情况下,max-heap是优先队列(priority queue)的底层实现机制.而这个实现机制中的m ...
随机推荐
- Lowest Common Ancestor of a Binary Tree, with Parent Pointer
Given a binary tree, find the lowest common ancestor of two given nodes in tree. Each node contains ...
- 微信 php 获取ticket
<?phpheader('content-type:text/html; charset=utf8');define('TOKEN', 'youtoken'); // TOKENdefine(' ...
- 自定义标签(TagSupport )
转载:http://zhuhuide2004.iteye.com/blog/555737 这个图太好了,拿下来,标注一下:
- cpu卡,sam卡原理
第一部分 CPU基础知识一.为什么用CPU卡IC卡从接口方式上分,可以分为接触式IC卡.非接触式IC卡及复合卡.从器件技术上分,可分为非加密存储卡.加密存储卡及CPU卡.非加密卡没有安全性,可以任意改 ...
- 关于 OnCloseQuery: 顺序、不能关机等(所有的windows的广播消息都是逐窗口传递的)——如果一个窗体的OnCloseQuery事件中如果写了代码那么WM_QUERYENDSESSION消息就传不过去了msg.result会返回0,关机事件也就停止了
系统关闭窗体的事件顺序为: OnCloseQuery ----> OnClose ----> OnDestroy 下面的代码说明问题: unit Unit3; interface uses ...
- 17.1.2?Replication Formats 复制格式:
17.1.2?Replication Formats 复制格式: 17.1.2.1 Advantages and Disadvantages of Statement-Based and Row-Ba ...
- HDU 3571 N-dimensional Sphere
高斯消元,今天数学死了无数次…… #include <cstdio> #include <cstring> #include <cmath> #include &l ...
- HDU 2067 小兔的棋盘
题解:卡特兰数的几何意义,所以答案就是卡特兰数的两倍 #include <cstdio> #include <iostream> using namespace std; #d ...
- C# windows ce编程-----我的第一次
最近公司要求开发抄表软件,软件分为PC端和手持终端(简称HHU),HHU是基于英文版的windows ce6.0操作系统,开发环境要求VS2005+SQLite数据库,开发语言为C#,因为是第一次基本 ...
- csv批量导入mysql命令
今天把从Kaggle上下载下来的csv数据导入mysql,想做个统计分析,怎奈csv文件有些大.所以仅仅能用mysql 命令导入,现mark下,以备以后不时之需: 1. 导入: 基本的语法: load ...