#include <iostream>
#include <cstdio>
#include <queue>
#include <vector> using namespace std; struct node
{
int priortity;
int value; friend bool operator<(node n1,node n2)
{
return n1.priortity < n2.priortity; // < 从大到小 , > 从小到大
}
}; int main()
{
const int len = ;
int i;
int a[len] = {,,,,}; //example 1:
priority_queue<int> qi; for(i = ; i < len; ++i)
{
qi.push(a[i]);
} for(i = ; i < len; ++i)
{
cout << qi.top() << endl;
qi.pop();
} //example 2:
priority_queue<int,vector<int>,greater<int> > qi2; // greater从小到大,less从大到小 for(i = ; i < len; ++i)
{
qi2.push(a[i]);
} for(i = ; i < len; ++i)
{
cout << qi2.top() << endl;
qi2.pop();
} //example 3:
priority_queue<node> qn;
node b[len];
b[].priortity = ; b[].value = ;
b[].priortity = ; b[].value = ;
b[].priortity = ; b[].value = ;
b[].priortity = ; b[].value = ;
b[].priortity = ; b[].value = ; for(i = ; i < len; ++i)
{
qn.push(b[i]);
} for(i = ; i < len; ++i)
{
cout << qn.top().priortity << "\t" << qn.top().value << endl;
qn.pop();
} return ;
}

参考文献:

http://wenku.baidu.com/link?url=_Y5TTAR5M4O2Eakp3lckzhc9ZkvGKp0Bqk-iSgxzUQOL5kuxGwwLZlFO1cq4ZqqvJV1HoNgurOftPRJvKp9Ng3S83c43tS1tQp0jxFHBp-u

模板:优先队列(priority_queue)的更多相关文章

  1. 浅谈C++ STL中的优先队列(priority_queue)

    从我以前的博文能看出来,我是一个队列爱好者,很多并不是一定需要用队列实现的算法我也会采用队列实现,主要是由于队列和人的直觉思维的一致性导致的. 今天讲一讲优先队列(priority_queue),实际 ...

  2. 优先队列priority_queue的简单应用

    优先队列 引入 优先队列是一种特殊以及强大的队列. 那么优先队列是什么呢? 说白了,就是一种功能强大的队列. 它的功能强大在哪里呢? 四个字:自动排序. 优先队列的头文件&&声明 头文 ...

  3. 9.优先队列,priority_queue

    #include <iostream> #include <queue> #include <deque> #include <list> using ...

  4. 892A. Greed#贪婪(优先队列priority_queue)

    题目出处:http://codeforces.com/problemset/problem/892/A 题目大意:有一些可乐(不一定装满),问能不能把所有可乐装进两个可乐瓶中 #include< ...

  5. 标准模板库中的优先队列(priority_queue)

    //C++数据结构与算法(第4版) Adam Drozdek 著  徐丹  吴伟敏<<清华大学出版社>> #include<queue> priority_queu ...

  6. 【STL】优先队列priority_queue详解+OpenJudge-4980拯救行动

    一.关于优先队列 队列(queue)这种东西广大OIer应该都不陌生,或者说,队列都不会你还学个卵啊(╯‵□′)╯︵┻━┻咳咳,通俗讲,队列是一种只允许从前端(队头)删除元素.从后端(队尾)插入元素的 ...

  7. 优先队列priority_queue的比较函数

    STL头文件:#include<queue> 优先队列: 默认从大到小排列:priority_queuee<node>q; 自定义优先级的三种方法: 1.重载操作符: bool ...

  8. C++ 优先队列priority_queue用法【转载】

    priority_queue 对于基本类型的使用方法相对简单.他的模板声明带有三个参数,priority_queue<Type, Container, Functional>Type 为数 ...

  9. [转]c++优先队列(priority_queue)用法详解

    既然是队列那么先要包含头文件#include <queue>, 他和queue不同的就在于我们可以自定义其中数据的优先级, 让优先级高的排在队列前面,优先出队 优先队列具有队列的所有特性, ...

随机推荐

  1. HW3.28

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  2. strust1.x中formbean的原理及作用

    from:     http://blog.csdn.net/tuiroger/article/details/3947896 今天张老师讲了一些比较重要的strust标签,<html:link ...

  3. MySql中启用InnoDB数据引擎的方法

    1.存储引擎是什么? Mysql中的数据用各种不同的技术存储在文件(或者内存)中.这些技术中的每一种技术都使用不同的存储机制.索引技巧.锁定水平并且最终提供广泛的不同的功能和能力.通过选择不同的技术, ...

  4. 部署ActiveMQ的Share File System Master-Slave

    之前在项目里用MQ是用单节点,因为业务量不大没有主从.这样风险很大,会有单点问题.新项目起来了,需要一个高可用的MQ,故研究了下AMQ的几种master-slave方式: 1.Pure Master- ...

  5. FFT(快速傅立叶算法 for java)

    package com.test.test2; public class FFT {     public static final int FFT_N_LOG = 10; // FFT_N_LOG ...

  6. new Date() iso不支持兼容性问题

    在IOS5以上版本(不包含IOS5)中的Safari浏览器能正确解释出Javascript中的 new Date('2013-10-21') 的日期对象. 但是在IOS5版本里面的Safari解释ne ...

  7. redis多实例运行

    有的时候会遇到一种情况,在一台服务器,一个redis实例会出现不够用的情况 那么这时我们可以创建多个实例,以满足不同的业务需求和功能需求 1.首先创建一个运行redis的普通用户 useradd -s ...

  8. IOS开发之TableView替换默认的checkmark为自定义图像

    直接上代码: On cellForRowAtIndexPath: UIButton*button =[UIButton buttonWithType:UIButtonTypeCustom];CGRec ...

  9. 礼仪或许就是尊重的还有一个说法——leo鉴书61

    <Leo鉴书(第1辑)>已登陆百度阅读,今后还将不断更新,免费下载地址:http://t.cn/RvawZEx 礼仪从字面上就区分成"礼"和"仪"两 ...

  10. [Webpack 2] Ensure all source files are included in test coverage reports with Webpack

    If you’re only instrumenting the files in your project that are under test then your code coverage r ...