最大堆:make_heap(vi.begin(),vi.end())

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int ia[] = {, , , , , , , , };
make_heap(ia, ia + );
for(int i = ; i < ; i++)
{
cout << ia[i] << " ";
}
cout << endl;
make_heap(ia, ia + );
pop_heap(ia, ia + );
cout << ia[] << endl;
}

最小堆:sort_heap(vi,vi+n)

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int ia[] = {, , , , , , , , };
sort_heap(ia, ia + );
for(int i = ; i < ; i++)
{
cout << ia[i] << " ";
}
cout << endl;
make_heap(ia, ia + );
pop_heap(ia, ia + );
cout << ia[] << endl;
}

Max-heap 取走根节点后完全二叉树的排序:

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int ia[] = {, , , , , , , , };
vector<int>vi(ia, ia + );
make_heap(vi.begin(), vi.end());
for(int i = ; i < vi.size(); i++)
{
cout << vi[i] << " ";
}
cout << endl;
pop_heap(vi.begin(), vi.end());
for(int i = ; i < vi.size(); ++i)
{
/* code */
cout << vi[i] << " ";
}
cout << endl;
for(int i = ; i < vi.size(); ++i)
{
/* code */
cout << vi[i] << " ";
}
cout << endl;
return ;
}

Max-heap && Min-heap && push_heap的更多相关文章

  1. implement min heap

    class MinHeap{ private ArrayList<Integer> arr; private int DEFAULT_LEN = 10; public MinHeap(){ ...

  2. find K maximum value from an unsorted array(implement min heap)

    Maintain a min-heap with size = k, to collect the result. //Find K minimum values from an unsorted a ...

  3. JAVA Shallow heap & Retained heap

    最近在研究内存泄漏的问题,在使用MAT工具中发现了Shallow heap & Retained heap,不懂. 然后在网上找了一些资料. Shallow Size 对象自身占用的内存大小, ...

  4. java.lang.OutOfMemoryError: PermGen space PermGen space & java.lang.OutOfMemoryError: Java heap space Heap siz

    java.lang.OutOfMemoryError: PermGen space PermGen space 由-XX:PermSize  -XX:MaxPermSize 引起 java.lang. ...

  5. 集合函数AVG,SUM,MAX,MIN

    需要计算这些值的平均值.使用函数AVG(),你可以返回一个字段中所有值的平均值. 假如你对你的站点进行一次较为复杂的民意调查.访问者可以在1到10之间投票,表示他们喜欢你站点的程度.你把投票结果保存在 ...

  6. 【转载】set_input_delay和set_output_delay的选项-max和-min的讨论

    转自:http://www.cnblogs.com/freshair_cnblog/archive/2012/09/12/2681060.html 一.存在背景分析 文档的说法是,set_input_ ...

  7. Oracle bug 使用max或min函数into到一个char类型报字符缓冲区太小的错误

    这个BUG出现会报错如下: selectto_char(max(RENEWAL_DATE)) intoM_YEAR_MONTH fromt_renewal_schedule; ORA-06502: P ...

  8. mvc 中Range中max和min值晚绑定

    对于Attribute : Range(min,max)的min和max必须在用的时候给,但是需求有时须要把这两个值存db.动态取出的.这时就须要razor帮忙了: @Html.TextBoxFor( ...

  9. SQL使用总结-like,MAX,MIN

    1. 时间索引不容许使用like 对时间索引适应like,会时间索引变成字符串操作,成为遍历动作,失去索引价值. 错误写法: EXPLAIN  SELECT AVG(data_value) AS av ...

  10. zip()函数,max()和min(),built-in function,import模块,read(),readlines(),write(),writelines(),with..as..文件处理方式

    zip()函数:将可迭代对象作为参数,将对象中的对应元素打包成一个个元组. #map()普通的输出例子 print(list(zip(('a','n','c'),(1,2,3)))) print(li ...

随机推荐

  1. Pro Git - 笔记1

    Getting Started About Version Control Local Version Control Systems Centralized Version Control Syst ...

  2. HDU 4441 Queue Sequence(优先队列+Treap树)(2012 Asia Tianjin Regional Contest)

    Problem Description There's a queue obeying the first in first out rule. Each time you can either pu ...

  3. 算法(12)Pascal's Triangle II

    题目:输出帕斯卡三角的第k行 思路:真没思路,发现几个easy的题不容易想!这里的大致思路是从后开始更新第k行!

  4. 微信PC端授权页面提示授权入口所在域名为空

    做第三方微信平台的时候做授权页面,用window.open方法从第三方平台页面打开新的授权标签页. 在IE浏览器上出问题,提示如下: 在chrome和firefox浏览器上正常. 搜了一下,发现微信是 ...

  5. 用WebService实现两个整数运算

    最近,项目开发中需要用到Web Service.自己在网上搜集资料.自己做了一个小例子,用来加深自己对Web Service理解. 概念:Web Service主要是为了使原来各孤立的站点之间的信息能 ...

  6. 2017 Multi-University Training Contest - Team 4 phone call(树+lca+并查集)

    题解: (并查集处理往上跳的时候,一定要先让u,v往上跳到并查集的祖先,不然会wa掉) 代码如下: #include <iostream> #include <algorithm&g ...

  7. null?对象?异常?到底应该如何返回错误信息

    这篇文章记录我的一些思考.在工作了一段时间之后. 问题的核心很简单:到底如何返回错误信息. 学生时代,见到过当时的老师的代码: if (foo() == null) { } 当然,这位老师是一位比较擅 ...

  8. [洛谷P2568]GCD

    题目大意:给你$n(1\leqslant n\leqslant 10^7)$,求$\displaystyle\sum\limits_{x=1}^n\displaystyle\sum\limits_{y ...

  9. [AT2558]Many Moves

    题目大意:有$n$个位置$1,2,\dots n$:你有两个棋子$A$和$B$,你要进行$q$次操作,第$i$次操作给定一个$x_i$,你要选择一个棋子移动到$x_i$:求两个棋子最小移动的步数之和. ...

  10. C&C++——C与C++知识点

    C++知识点系列之一(转+整理) 编程时类声明后面千万不要忘了加分号,不然会出现很多错误!! c系列之一一.#include “filename.h”和#include<filename.h&g ...