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 - ...
随机推荐
- 牛客提高D6t3 分班问题
分析 就就就是推柿子 看官方题解吧/px 代码 #include<iostream> #include<cstdio> #include<cstring> #inc ...
- 升级至webpack4.x踩坑记(热更新局部更新失败的问题修复)
零.前言 webpack升级的时候,会碰到各种个样的问题,大多数网上都能查到解决方案最简单的方案. 思路如下: 1.把css-loader,xxxloader等依赖都升级到最新 2.根据webpack ...
- Oralce-资源配置PROFILE
profile:作为用户配置文件,它是密码限制,资源限制的命名集合 在安装数据库时,Oracle自动会建立名为default的默认配置文件 使用profile文件时,要注意以下几点: 建立用户时,如果 ...
- 定制化fiddler会话列表字段
前言:fiddler默认会话列表已有一些显示字段,可能并不是我们需要的,我们可以自行定制化. 以会话耗时为例: 目录 1.方法一:修改js脚本 2.方法二:通过菜单栏设置 1.方法一:修改js脚本 点 ...
- Scratch可视化的编程工具
1.是什么? 在线编程网址 是一个编程软件,但是不涉及编程语言,是针对青少年开发的编程积木模块. 2.软件的目的是什么? 激发青少年对编程的兴趣 3.怎么用呢? 软件内部是很多积木模块,需要明白每块是 ...
- Yaconf – 一个高性能的配置管理扩展
鸟哥出品:http://www.laruence.com/2015/06/12/3051.html 首先说说, 这个是干啥的. 我见过很多的项目中, 用PHP文件做配置的, 一个config目录下可能 ...
- JavaScript高级程序设计(第3版) 第四章(变量、作用域和内存问题)
4.1 基本类型和引用类型的值 1.基本类型的值是(简单的数据段),引用类型的值是(保存在内存中的对象). 基本类型的值在内存中占据固定大小的空间,因此被保存在栈中.(lifo ...
- VScode 常用快捷键 2019
窗口操作 Ctrl + b : 显示/隐藏左侧工作区文件目录 View Appearance show Activity bar : 最左侧工具栏 显示/隐藏 Preferences ...
- MySQL-第六篇DML语句
1.DML主要操作数据表里的数据,主要完成3个任务: 1>insert:插入数据.格式:insert into ... 2>delete:删除数据.格式:delete from ... 3 ...
- /dev/random vs /dev/urandom
If you want random data in a Linux/Unix type OS, the standard way to do so is to use /dev/random or ...