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().

最新文章

  1. ASP.NET MVC之路由深究
  2. linux rlwrap
  3. [bzoj1911][Apio2010]特别行动队
  4. autocomplete一次返回多个值,并且选定后填到不同的Textbox中
  5. Comware 架构理解
  6. [WCF]IIS部署到新系统
  7. 浅谈ListBox控件,将对象封装在listBox中,在ListBox中显示对象中某个属性,在ListBox中移除和移动信息
  8. js获取下拉列表(select)选中项的值和文本
  9. 我的第一个MVC项目
  10. MOSS 2010 无法同步用户配置文件
  11. poj1364(差分约束系统)
  12. [CSDN_Markdown] 使用LaTeX写矩阵
  13. Oarcle之组函数
  14. Hdoj 2899.Strange fuction 题解
  15. nodejs,mongodb不同时区问题
  16. 剑指Offer 40. 数组中只出现一次的数字 (数组)
  17. Manjaro 初始配置----anaconda-pycharm-opencv-tensorflow
  18. 力扣(LeetCode)69. x 的平方根
  19. java再次学习
  20. Kali Linux 与 BackTrack Linux

热门文章

  1. 移动端调试 — Pure|微信环境调试方案|App环境调试方案
  2. 【GIS数据格式】ArcInfo Binary Grid Format
  3. jmeter3.0+ant1.10+jenkins实现接口自动化并发送邮件
  4. Nginx+Tomcat实现单IP、多域名、多站点的访问
  5. mysql定时备份shell脚本
  6. vue的概述
  7. Linux多线程服务器端编程
  8. [Python3 练习] 010 找出藏在字符串中的“密码”
  9. 【Python—参数】*arg与**kwargs参数的用法
  10. 前端最常用的跨域方式--jsonp