博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++ priority_queue用法(大顶堆,小顶堆)
阅读量:6913 次
发布时间:2019-06-27

本文共 1501 字,大约阅读时间需要 5 分钟。

hot3.png

template <class T, class Container = vector<T>,
class Compare = less<typename Container::value_type> > class priority_queue;

parameters

例子

#include 
#include
#include
#include
#include
#include
#include
#include
using namespace std;/** 默认比较函数为less, 大顶堆 **/void defaultCmpLess() { cout << "=========defaultCmpLess(big heap)========" << endl; priority_queue
q; for (int i = 0; i < 10; i++) { q.push(rand()%20); } while (!q.empty()) { cout << q.top() << " "; q.pop(); } cout <
<< endl; priority_queue
, greater
> q; for (int i = 0; i < 10; i++) { q.push(rand()%20); } while (!q.empty()) { cout << q.top() << " "; q.pop(); } cout <
b.y;}/** 运算符重载 **/void overloadOperator() { cout << "=========overload Operator< =========" << endl; cout << "a.x < b.x; a.y > b.y" << endl; priority_queue
q; for (int i = 0; i < 10; i++) { q.push( Node( rand()%20, rand()%20 ) ); } while (!q.empty()) { cout << q.top().x << "," << q.top().y << endl; q.pop(); } cout << endl; }//=========================/** 自构建比较函数 **/struct cmp2{ bool operator()(int a, int b) { return a < b; }};void designCmp() { cout << "=========designCmp========" << endl; cout << "operator a
<< endl; priority_queue
, cmp2 > q; for (int i = 0; i < 10; i++) { q.push(rand()%20); } while (!q.empty()) { cout << q.top() << " "; q.pop(); } cout <
b.y 19,1 19,9 19,18 17,6 16,15 12,7 10,13 9,17 3,9 0,13 =========designCmp======== operator a

转载于:https://my.oschina.net/Jerrymingzj/blog/803829

你可能感兴趣的文章
漂亮的title提示信息
查看>>
bootstrap-分页-禁用和激活状态
查看>>
文件的递归遍历
查看>>
我的友情链接
查看>>
Python读写CSV文件
查看>>
EBB-7、认识bash
查看>>
CentOS 5.8 64位 源码安装mysql5.5.28
查看>>
windows下后台运行程序
查看>>
传统的MapReduce框架慢在那里
查看>>
Linux下修改Mysql的用户(root)的密码
查看>>
萌新的Linux学习之路(十二)---软件安装
查看>>
2012数学建模A题
查看>>
20个java异常处理最佳实践
查看>>
centos架设pptp服务:并测试windos客户端、Linux客户端!
查看>>
【c#】BackgroundWorker类的使用方法
查看>>
【NetApp】启用smb2.0
查看>>
Nginx与django+uwsgi成功勾搭的始末(上)
查看>>
创业的国度
查看>>
001作业题
查看>>
字节字符转换流
查看>>