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 - ...
随机推荐
- 屏幕分辨率测试工具(舍弃)---chrome开发者工具devTools(强烈建议系统学习)
2019-01-25 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// ...
- SqlServer 查看缓存 并合理设置最大内存
SqlServer 服务器运行一段时间发现内存逐渐增长 飙升到98%了 解决方法: 重启主机 重启SqlServer服务 设置最大内存 前两种方法不太适合线上环境 且指标不治本 建议用设置最大内存 如 ...
- leetcode 292. Nim游戏(python)
你和你的朋友,两个人一起玩 Nim 游戏:桌子上有一堆石头,每次你们轮流拿掉 1 - 3 块石头. 拿掉最后一块石头的人就是获胜者.你作为先手. 你们是聪明人,每一步都是最优解. 编写一个函数,来判断 ...
- Python中import的使用方法
源文出处: "import"的本质参照: Python中import机制 python导入自定义模块和包
- JQuery 字符串转时间格式
//字符串转时间格式 function getDate(strDate) { var date = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$) ...
- VS代码自动补全功能
VS代码自动补全功能 新建工程后,依次打开 工具>>代码段管理器>>选择C++>>点击 添加(A)...按钮 ,设置你的代码块的目录 复制以下代码并存为note.s ...
- Windows系统CVE整理
CVE-2018-8420(RCE) 受影响版本: Microsoft Windows 10 Version 1607 for 32-bit Systems Microsoft Windows 10 ...
- 06(H5*)Vue第五天、第六天 Vue常见命令
常见的Vue命令 全局安装 1:npm i webpack -g 全局安装webpack. 保存到项目中 -S 2:npm i webpack --save-dev 安装到项目依赖中. 3 ...
- Struts2之上传
单文件上传 上传页面 <%@ page language="java" contentType="text/html; charset=UTF-8" pa ...
- kmp(循环节)
Cyclic Nacklace Problem Description CC always becomes very depressed at the end of this month, he ha ...