#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. Headless MSBuild Support for SSDT (*.sqlproj) Projects [利用msbuild自动化部署 .sqlproj]- 摘自网络

    Update: breaking change: http://sqlproj.com/index.php/2012/10/dacfx-sept-2012-updates-break-headless ...

  2. Redis和Memcache的对比

    我这段时间在用redis,感觉挺方便的,但比较疑惑在选择内存数据库的时候到底什么时候选择redis,什么时候选择memcache,然后就查到下面对应的资料,是来自redis作者的说法(stackove ...

  3. Go语言简介

    Go语言简介 - Go语言是由Google开发的一个开源项目,目的之一为了提高开发人员的编程效率. Go语言简介 Go语言是由Google开发的一个开源项目,目的之一为了提高开发人员的编程效率. Go ...

  4. 第一章 Windows NT System Components

    Page 3. The focus(焦点) of this book is Windows NT file system and the interaction(交互) of the file sys ...

  5. Struts文件上传机制

    1首先建立文件上传jsp页面如下 <form action="" method="post" enctype="multipart/form-d ...

  6. php排序之冒泡排序

    冒泡排序比较简单.作为很多公司面试笔试题常常出现,要求手写该排序算法.双层循环,不断的与后面的比较,如果大于后面的,调换两者顺序即可. 演示效果如图: 代码如下: <?php function ...

  7. Delphi 调用批处理

    uses ShellApi; procedure TForm1.Button1Click(Sender: TObject); var filename, Path: string; begin fil ...

  8. Ubuntu Server 12.04 静态IP简洁配置

    PS:很长时间没使用Ubuntu了,刚才安装个Ubuntu Server 12.04做测试.Ubuntu的网络设置跟Redhat系是不一样的,配置IP时发现跟以前的Ubuntu桌面版本也有所不同,记录 ...

  9. My安装Eclipse三种方法插件

    Eclipse它是一个开源项目,但非常需要手动集成插件,MyEclipse在Eclipse插件.但非常多时候MyEclipse相同须要再次安装插件,插件安装有三种方法,以下以SVN为例.具体阐述. E ...

  10. ios的@property属性和@synthesize属性

    当你定义了一系列的变量时,需要写很多的getter和setter方法,而且它们的形式都是差不多的,,所以Xcode提供了@property 和@synthesize属性,@property用在 .h ...