初始化:

priority_queue<int>                           maxPQ;

priority_queue<int,vector<int>,greater<int> > minPQ;

算法:

minPQ.push( 4 )

代码:

 #include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <string>
using namespace std; // Empty the priority queue and print its contents.
template <typename PriorityQueue>
void dumpContents( const string & msg, PriorityQueue & pq )
{
cout << msg << ":" << endl;
while( !pq.empty( ) )
{
cout << pq.top( ) << endl;
pq.pop( );
}
} // Do some inserts and removes (done in dumpContents).
int main( )
{
priority_queue<int> maxPQ;
priority_queue<int,vector<int>,greater<int> > minPQ; minPQ.push( ); minPQ.push( ); minPQ.push( );
maxPQ.push( ); maxPQ.push( ); maxPQ.push( ); dumpContents( "minPQ", minPQ );
dumpContents( "maxPQ", maxPQ ); return ;
}

输出:

$ ./a.exe
minPQ: maxPQ:

【STL】-priority_queue的用法的更多相关文章

  1. STL priority_queue 常见用法详解

    <算法笔记>学习笔记 priority_queue 常见用法详解 //priority_queue又称优先队列,其底层时用堆来实现的. //在优先队列中,队首元素一定是当前队列中优先级最高 ...

  2. 详解C++ STL priority_queue 容器

    详解C++ STL priority_queue 容器 本篇随笔简单介绍一下\(C++STL\)中\(priority_queue\)容器的使用方法和常见的使用技巧. priority_queue容器 ...

  3. STL - priority_queue(优先队列)

    优先级队列priority_queue 最大值优先级队列.最小值优先级队列 优先级队列适配器 STL priority_queue 用来开发一些特殊的应用. priority_queue<int ...

  4. C++中的STL中map用法详解(转)

    原文地址: https://www.cnblogs.com/fnlingnzb-learner/p/5833051.html C++中的STL中map用法详解   Map是STL的一个关联容器,它提供 ...

  5. STL的其他用法(adjacent_find, find_first_of, sort_heap, merge, binary_search)总结

    2017-08-20 17:26:07 writer:pprp 1.adjacent_find() 下面是源码实现: template <class ForwardIterator> Fo ...

  6. C++-STL:vector用法总结

    目录 简介 用法 1. 头文件 2. vector的声明及初始化 3. vector基本操作 简介 vector,是同一类型的对象的集合,这一集合可看作可变大小的数组,是顺序容器的一种.相比于数组,应 ...

  7. 【转载】C++ STL priority_queue用法

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

  8. C++STL 常用 函数 用法

    学完c++快一年了,感觉很有遗憾,因为一直没有感觉到c++的强大之处,当时最大的感觉就是这个东西的输入输出比C语言要简单好写. 后来我发现了qt,opencv,opengl,原来,c++好玩的狠. 在 ...

  9. (转)priority_queue的用法

    priority_queue调用 STL里面的 make_heap(), pop_heap(), push_heap() 算法实现,也算是堆的另外一种形式.先写一个用 STL 里面堆算法实现的与真正的 ...

随机推荐

  1. Android 面试题总结

    Android 面试题总结(不断更新) 1.INETNT几种有关Activit的启动方式FLAG_ACTIVITY_BROUGHT_TO_FRONT 将ACTIVITY带到最前面FLAG_ACTIVI ...

  2. uva 11324 The Largest Clique

    vjudge 上题目链接:uva 11324 scc + dp,根据大白书上的思路:" 同一个强连通分量中的点要么都选,要么不选.把强连通分量收缩点后得到SCC图,让每个SCC结点的权等于它 ...

  3. China Brain Project: Basic Neuroscience, Brain Diseases, and Brain-Inspired Computing

    日前,中国科学院神经科学研究所.中国科学院脑科学与智能技术卓越创新中心.香港科技大学生命科学部和分子神经科学国家重点实验室.中国科技大学自动化研究所在 Cell 上联合发表了一篇概述论文<Chi ...

  4. 慕课网:C++ & 数据结构

    课程链接:james_yuan的课程 这部分太枯燥了,如果教材难度稍大,根本就学不下去,所以就先看看通俗的视频吧. 课程目录 1.C++远征之起航篇 - C++亮点尽在其中 2.C++远征之离港篇 - ...

  5. 【转】Android应用开发之PNG、IconFont、SVG图标资源优化详解

    1 背景 最近因为一些个人私事导致好久没写博客了,多事之年总算要过去了,突然没了动力,所以赶紧先拿个最近项目中重构的一个小知识点充下数,老题重谈. 在我们App开发中大家可能都会有过如下痛疾(程序员和 ...

  6. dom4j如何解析xml

    简单解析自己定义的xml文件,首先,给解析xml文件的类来个构造方法: public xmlData(File xmlFile) { file = xmlFile; try { saxReader = ...

  7. 微信小程序初体验(上)

    版权声明:本文由练小习原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/204 来源:腾云阁 https://www.qclo ...

  8. 腾讯云从零部署nodejs站点

    版权声明:本文由袁飞翔原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/176 来源:腾云阁 https://www.qclo ...

  9. 一个最简html5文档来说明html5的新特性和写法

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="utf-8&quo ...

  10. java中的异常和处理

    算术异常类:ArithmeticExecption 空指针异常类:NullPointerException 类型强制转换异常:ClassCastException 数组负下标异常:NegativeAr ...