STL中的make_heap、push_heap、pop_heap示例程序
来源:互联网 发布:软件陷阱 编辑:程序博客网 时间:2024/05/18 14:23
// alg_pop_heap.cpp// compile with: /EHsc#include <vector>#include <algorithm>#include <functional>#include <iostream>int main( ) { using namespace std; vector <int> v1; vector <int>::iterator Iter1, Iter2; int i; for ( i = 1 ; i <= 9 ; i++ ) v1.push_back( i ); // Make v1 a heap with default less than ordering random_shuffle( v1.begin( ), v1.end( ) ); make_heap ( v1.begin( ), v1.end( ) ); cout << "The heaped version of vector v1 is ( " ; for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) cout << *Iter1 << " "; cout << ")." << endl; // Add an element to the back of the heap v1.push_back( 10 ); push_heap( v1.begin( ), v1.end( ) ); cout << "The reheaped v1 with 10 added is ( " ; for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) cout << *Iter1 << " "; cout << ")." << endl; // Remove the largest element from the heap pop_heap( v1.begin( ), v1.end( ) ); cout << "The heap v1 with 10 removed is ( " ; for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) cout << *Iter1 << " "; cout << ")." << endl << endl; // Make v1 a heap with greater-than ordering with a 0 element make_heap ( v1.begin( ), v1.end( ), greater<int>( ) ); v1.push_back( 0 ); push_heap( v1.begin( ), v1.end( ), greater<int>( ) ); cout << "The 'greater than' reheaped v1 puts the smallest " << "element first:\n ( " ; for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) cout << *Iter1 << " "; cout << ")." << endl; // Application of pop_heap to remove the smallest element pop_heap( v1.begin( ), v1.end( ), greater<int>( ) ); cout << "The 'greater than' heaped v1 with the smallest element\n " << "removed from the heap is: ( " ; for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) cout << *Iter1 << " "; cout << ")." << endl;}
The heaped version of vector v1 is ( 9 5 8 4 1 6 7 2 3 ).The reheaped v1 with 10 added is ( 10 9 8 4 5 6 7 2 3 1 ).The heap v1 with 10 removed is ( 9 5 8 4 1 6 7 2 3 10 ).The 'greater than' reheaped v1 puts the smallest element first: ( 0 1 6 3 2 8 7 4 9 10 5 ).The 'greater than' heaped v1 with the smallest element removed from the heap is: ( 1 2 6 3 5 8 7 4 9 10 0 ).
- STL中的make_heap、push_heap、pop_heap示例程序
- STL---heap概述,make_heap,sort_heap,pop_heap,push_heap。
- STL---heap概述,make_heap,sort_heap,pop_heap,push_heap
- STL---heap概述,make_heap,sort_heap,pop_heap,push_heap
- STL---heap概述,make_heap,sort_heap,pop_heap,push_heap。
- STL---heap概述,make_heap,sort_heap,pop_heap,push_heap
- make_heap(), pop_heap(), push_heap()用法
- make_heap(), pop_heap(), push_heap()用法
- priority_queue 调用 STL里面的 make_heap(), pop_heap(), push_heap() 算法
- STL中heap相关函数的用法:make_heap,push_heap,pop_heap...
- 【STL】Heap算法——push_heap、pop_heap、sort_heap、make_heap
- make_heap, push_heap, pop_heap, 的使用
- c++ make_heap, pop_heap, push_heap, sort_heap详解
- 【优先队列】【堆】STL之priority_queue、make_heap()、push_heap()、pop_heap()、容器适配器
- C++中堆的应用:make_heap, pop_heap, push_heap, sort_heap, priority_queue
- C++中堆的应用:make_heap, pop_heap, push_heap, sort_heap
- STL algorithm算法pop_heap,push_heap(45)
- C++ make_heap,push_heap,pop_heap,sort_heap(以最大的K个数为例)
- SBL-SCM-00018: Could not open connection to Siebel Gateway configuration store
- 关于hashCode的使用
- 多线程例子
- WPF Snippet - Reliably Getting The Mouse Position
- Spring 注解总结
- STL中的make_heap、push_heap、pop_heap示例程序
- Linux压缩解压命令
- android 系统 makefile文件(Android.mk)组织结构
- malloc/free与new/delete的区别
- Convert Static to Dynamic Construction -- 静态到动态构造转换
- 最小生成树 prim
- APP支持不同的设备 之 支持不同版本的平台
- windows上用eclipse 开发django和第一个hello world
- JMeter2.9选择语言