http://www.cplusplus.com/reference/queue/priority_queue/

priority_queue 的top始终保持着为一堆数据中的最大元素。

读取最小 O(1)

插入和删除 lg(n)

(真是又简便又好用,难怪g不要我,当时连这个都不会写,sigh...)

#include <iostream>
#include <vector>
#include <queue>
using namespace std; class greater_class{
public:
bool operator()(int a,int b)
{
return a > b;
}
};
int main()
{
vector<int> num; priority_queue<int,vector<int>,greater_class> myQueue; myQueue.push();
myQueue.push();
myQueue.push(); cout<< myQueue.top();
myQueue.pop();
myQueue.push(); cout<<"print all data in priority_queue"<<endl;
while(myQueue.empty() == false)
{
cout<< myQueue.top() << " ";
myQueue.pop();
}
}

priority_queue 示例的更多相关文章

  1. STL中的优先级队列priority_queue

    priority_queue(queue类似)完全以底部容器为根据,再加上二叉堆(大根堆或者小根堆)的实现原理,所以其实现非常简单,缺省情况下priority_queue以vector作为底部容器.另 ...

  2. 容器适配器(stack、 queue 、priority_queue)源码浅析与使用示例

    一.容器适配器 stack queue priority_queue stack.queue.priority_queue 都不支持任一种迭代器,它们都是容器适配器类型,stack是用vector/d ...

  3. 5.1 stack,queue以及priority_queue

    *:stack 使用要包含头文件stack,栈是一种先进后出的元素序列,删除和访问只能对栈顶的元素(最后一个添加的元素)进行,并且添加元素只能添加到栈顶.栈内的元素不能访问,要想访问先要删除其上方的所 ...

  4. (转)【C++ STL】细数C++ STL 的那些事 -- priority_queue(优先队列)

    装载自http://blog.csdn.net/tianshuai1111/article/details/7652553 一,概述 priority_queue是拥有权值观念的queue,它允许加入 ...

  5. 【转】priority_queue优先队列

    转自:http://www.cppblog.com/shyli/archive/2007/04/06/21366.html http://www.cppblog.com/shyli/archive/2 ...

  6. 牛客网 牛客练习赛7 B.购物-STL(priority_queue)

    B.购物 时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 32768K,其他语言65536K64bit IO Format: %lld 题目描述 在遥远的东方,有一家糖果专卖店 这家糖果 ...

  7. priority_queue用法(转载)

    关于priority_queue 1,关于STL中的priority_queue:确定用top()查看顶部元素时,该元素是具有最高优先级的一个元素. 调用pop()删除之后,将促使下一个元素进入该位置 ...

  8. STL学习笔记6 -- 栈stack 、队列queue 和优先级priority_queue 三者比较

    栈stack  .队列queue  和优先级priority_queue 三者比较 默认下stack 和queue 基于deque 容器实现,priority_queue 则基于vector 容器实现 ...

  9. poj 3253 Fence Repair(priority_queue)

    Fence Repair Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 40465   Accepted: 13229 De ...

随机推荐

  1. [vivado系列]Zynq开发常用文档

    时间:2016.06.13 目的:阶段性总结学习的策略 ------------------------------------------------------------------------ ...

  2. eclipse重定向输入输出到文件

    最近在学习算法第四版,为了要用作者给的测试数据alg4-data,需要将数据直接导入到程序中.在作者的示例代码里用了重定向来做这个事情,但是在eclipse里使用重定向很不方便,查了很多资料,都说是在 ...

  3. 关于c#调用c编译器

    这个已经过了好久了具体的实现代码没得,但是大致思路自己整理了一下: 首先要调用c编译器,process.start(): 之后需要自己来进行编译器对代码执行的命令.

  4. subversion(SVN)常规使用

    语法: svn <subcommand> [options] [args]      使用“svn help <subcommand>” 显示子命令的帮助信息.      使用 ...

  5. 学习shell脚本笔记

    1.if 是单分支语句,使用格式如下: if condition ; then statement ….. fi 2.if … else 是双分支语句,使用格式如下: if condition ; t ...

  6. php中$row=mysql_fetch_row()出错问题

    在写php时用到这样一个问题,代码如下: $sql="select * from sina"; mysql_connect("localhost"," ...

  7. Python第一模块

    一.Python简介 二.Python种类 三.Python环境  windows: 1.需要配置环境变量 2.更新:卸载重装 linux:1.常用命令: 查看默认Python版本 Python -V ...

  8. 转载:Solr的自动完成实现方式(第二部分:Suggester方式)

    转自:http://www.cnblogs.com/ibook360/archive/2011/11/30/2269077.html 在Solr的自动完成/自动补充实现介绍(第一部分) 中我介绍了怎么 ...

  9. Spring Framework------>version4.3.5.RELAESE----->Reference Documentation学习心得----->关于spring framework中的beans

    Spring framework中的beans 1.概述 bean其实就是各个类实例化后的对象,即objects spring framework的IOC容器所管理的基本单元就是bean spring ...

  10. xml/map转换器,递归设计思路

    xml/map转换器 图片:http://pan.baidu.com/s/1nuKJD13 应用场景,为什么要把xml转map?我直接用jdom,dom4j操作不行吗? 如果你了解模板引擎(像velo ...