最大堆: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. memcached简单介绍及在django中的使用

    什么是memcached? Memcached是一个高性能的分布式的内存对象缓存系统,全世界有不少公司采用这个缓存项目来构建大负载的网站,来分担数据库的压力.Memcached是通过在内存里维护一个统 ...

  2. 在ubuntu下 使用Jetty 和 Maven 开发 HelloWorld

    1 安装JDK 我以前安装过,这里就不说了. 2 安装maven 去官网下载 解压 添加环境变量   gedit ~/.bashrc export JETTY_HOME=/home/roc/libs/ ...

  3. 另外一种C#多选下拉框

    链接: https://pan.baidu.com/s/1tnLgC9P_V8y9qHTYSg8xGA 密码: cwxj

  4. laravel 学习随笔(一)

    1.路由参数:路由参数总是通过花括号进行包裹,参数在路由被执行时会被传递到路由的闭包.(路由参数不能包含“-”字符,如有需要可以用“_”代替):

  5. Internet History,Technology and Security

    Internet History,Technology and Security(简单记录) First Week High Stakes Research in Computing,and Comm ...

  6. PokeCats开发者日志(一)

      现在是PokeCats游戏开发的第三天的上午,突然心血来潮想记录一下这个开发过程,于是写起了开发者日志. day1   作为一只ACM退役喵,寒假回家,闲着没事,天天在召唤师峡谷里闲逛也挺没意思的 ...

  7. Flink 任务打包、提交

    一.Flink版本 flink-1.6.1-bin-hadoop26-scala_2.11 二.Flink任务打包 笔者将写好的flink计算任务代码发到服务器(ubuntu16.04),在服务器端进 ...

  8. Why is the ibdata1 file continuously growing in MySQL?

    We receive this question about the ibdata1 file in MySQL very often in Percona Support. The panic st ...

  9. 状压DP初识~~炮兵阵地

    炮兵阵地 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 31718   Accepted: 12253 Descriptio ...

  10. CMU Bomblab 答案

    室友拉我做的... http://csapp.cs.cmu.edu/3e/labs.html Border relations with Canada have never been better. ...