boost heap
1. using boost::heap::priority_queue
#include <boost/heap/priority_queue.hpp>
#include <iostream> using namespace boost::heap; int main() {
priority_queue<int> pq;
pq.push();
pq.push();
pq.push(); for (int i : pq) {
std::cout << i << std::endl;
} priority_queue<int> pq2;
pq2.push();
std::cout << std::boolalpha << (pq > pq2) << std::endl;
return ;
}
In general this class behaves like std::priority_queue, except it allows you to iterate over elements. The order of elements returned in the iteration is random.
Objects of type boost::heap::priority_queue can be compared with each other. The comparison above returns true because pq has more elements than pq2. If both queues had the same number of elements, the elements would be compared in pairs.
2. using boost::heap::binomial_heap
#include <boost/heap/binomial_heap.hpp>
#include <iostream> using namespace boost::heap; int main()
{
binomial_heap<int> bh;
bh.push();
bh.push();
bh.push(); binomial_heap<int> bh2;
bh2.push();
bh.merge(bh2); for (auto it = bh.ordered_begin(); it != bh.ordered_end(); ++it)
std::cout << *it << '\n';
std::cout << std::boolalpha << bh2.empty() << std::endl;
return ;
}
输出为:
4
3
2
1
true
boost::heap::binomial_heap in addition to allowing you to iterate over elements in priority order, it also lets you merge priority queues. Elements from one queue can be added to another queue. As above, calls merge() on the queue bh. The queue bh2 is passed as a parameter. The call to merge() moves the number 4 from bh2 to bh. After the call, bh contains four numbers, and bh2 is empty. The for loop calls ordered_begin() and ordered_end() on bh. ordered_begin() returns an iterator that iterates from high priority elements to low priority elements.
4. update
#include <boost/heap/binomial_heap.hpp>
#include <iostream> using namespace boost::heap; int main()
{
binomial_heap<int> bh;
auto handle = bh.push();
bh.push();
bh.push(); bh.update(handle, ); std::cout << bh.top() << std::endl;
return ;
}
As above saves a handle returned by push(), making it possible to access the number 2 stored in bh.
update() is a member function of boost::heap::binomial_heap that can be called to change an element. Afterwards, the element with the highest priority, now 4, is fetched with top().
boost heap的更多相关文章
- Google C++ Style Guide
Background C++ is one of the main development languages used by many of Google's open-source project ...
- zz A list of open source C++ libraries
A list of open source C++ libraries < cpp | links http://en.cppreference.com/w/cpp/links/libs Th ...
- Google C++ 代码规范
Google C++ Style Guide Table of Contents Header Files Self-contained Headers The #define Guard For ...
- c++开发规范
目录 1. 头文件 1.1. Self-contained 头文件 1.2. #define 保护 1.3. 前置声明 1.4. 内联函数 1.5. #include 的路径及顺序 2. 作用域 2. ...
- 你说你会C++? —— 智能指针
智能指针的设计初衷是: C++中没有提供自己主动回收内存的机制,每次new对象之后都须要手动delete.稍不注意就memory leak. 智能指针能够解决上面遇到的问题. C++中常见的 ...
- Google开源项目风格指南
Google开源项目风格指南 来源 https://github.com/zh-google-styleguide/zh-google-styleguide Google 开源项目风格指南 (中文版) ...
- [Guide]Google C++ Style Guide
0.0 扉页 项目主页 Google Style Guide Google 开源项目风格指南 -中文版 0.1 译者前言 Google 经常会发布一些开源项目, 意味着会接受来自其他代码贡献者的代码. ...
- Boost 1.61.0 Library Documentation
http://www.boost.org/doc/libs/1_61_0/ Boost 1.61.0 Library Documentation Accumulators Framework for ...
- boost库的安装,使用,介绍,库分类
1)首先去官网下载boost源码安装包:http://www.boost.org/ 选择下载对应的boost源码包.本次下载使用的是 boost_1_60_0.tar.gz (2)解压文件:tar - ...
随机推荐
- sql常用 语句总结
一,插入一个新字段:ALTER TABLE +表名+ADD COLUMN(字段名+ 类型) sql1 = 'ALTER TABLE klkl_4s_shop ADD COLUMN (name_rea ...
- Flueme学习之路(一)Flume的基础介绍
背景 Hadoop业务的整体开发流程: 从Hadoop的业务开发流程中可以看出,在大数据的业务处理流程中,对于数据的采集是十分重要的一步,也是不可避免的一步. 许多公司的平台每天会产生大量的日 ...
- 2017年度最具商业价值人工智能公司TOP50 榜单发布
2017年度最具商业价值人工智能公司TOP50 榜单发布 未来最有赚钱潜力的50个人工智能项目都在这里了. 经过了60年的发展,人工智能在2017年,正式走向应用的元年. 从今年起,人工智能首次被写入 ...
- 1208D Restore Permutation
题目大意 给你一个序列s 让你求一个1~n的序列 使得对于第i个位置它前面所有小于p[i]的数的和恰好为s[i] 分析 我们可以从后往前确定每一位 每次一二分找到恰好等于s[i]的数 但是我们发现这样 ...
- 为什么每次打出的包都是Release版本呢?
参考了:xcodebuild命令 https://www.cnblogs.com/liuluoxing/p/8622108.html 重新打个包,验证一下想法
- Linux实用技巧--隧道
平时开发过程中,可能会遇到一些网络问题,比如npm install 一些依赖包.本地电脑是可以,没有问题.但是测试环境服务器,由于公司内部网络安全限制,不可以随意访问外部网络.因此下载一个依赖包就变得 ...
- 解决Win7部分便笺的元数据已被损坏的方法
Win7部分便笺的元数据已被损坏的方法 我们使用键盘上"Win+F"组合键搜索功能,直接找到"inkobj.dll"这个文件,一般会搜索出来好多,先随便选一个. ...
- JAVA File的创建及相对路径绝对路径
http://blog.sina.com.cn/s/blog_9386f17b0100w2vv.html JAVA File的创建及相对路径绝对路径 (2011-12-09 08:27:56) 转载▼ ...
- Vagrant 手册之网络 - 概述及基本用法
原文地址 - 概述 原文地址 - 基本用法 为了访问创建的 Vagrant 环境,Vagrant 为端口转发.连接公共网络.创建私有网络等功能暴露了一些高层网络选项. 高层网络选项用于提供可以跨 pr ...
- Go错误处理机制及自定义错误
错误处理机制: 先看一段代码:看看输出什么? package mainimport "fmt" func test() { num1 := 10 num2 := 0 res := ...