stl make_heap_通过使用make_heap()创建堆| C ++ STL
stl make_heap
What is Heap Data structure?
什么是堆數(shù)據(jù)結(jié)構(gòu)?
Heap is a tree-based which is used for fast retrieval of largest (max heap) or smallest (min heap) element. This DS is used in the priority queue, prims algo, heap sort and many more.
堆是基于樹的,用于快速檢索最大(最大堆)或最小(最小堆)元素。 該DS用于優(yōu)先級隊列,原始算法,堆排序等。
make_heap()函數(shù) (make_heap() function)
Syntax:
句法:
make_heap( arg1, agr2 ,[arg3])Here,
這里,
arg1 = pointer or iterator to starting of the number list
arg1 =指向數(shù)字列表開頭的指針或迭代器
arg2 = pointer or iterator to ending of the number list
arg2 =指向數(shù)字列表結(jié)尾的指針或迭代器
arg3 = optional, use to change default nature of the heap i.e is max heap to min heap
arg3 =可選,用于更改堆的默認(rèn)性質(zhì),即將最大堆更改為最小堆
1)代碼演示make_heap()[最大堆]的用法 (1) Code to demonstrate use of make_heap()[max heap])
#include <bits/stdc++.h> using namespace std;#define MAX 5int main() {int array[MAX]={6,3,6,17,8};//Max Heap createdmake_heap(array,array+MAX);cout<<array[0]<<endl;return 0; }Output
輸出量
17 .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}} .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}}2)代碼演示make_heap()[最小堆]的用法 (2) Code to demonstrate use of make_heap()[min heap])
#include <bits/stdc++.h> using namespace std; #define MAX 5bool compare(int a, int b) {if(a<b)return 0; //change to 1 if max heap requiredelse return 1; //change to 0 if max heap required }int main() {int array[MAX]={6,3,6,17,8};make_heap(array,array+MAX,compare);cout<<array[0]<<endl;return 0; }Output
輸出量
3翻譯自: https://www.includehelp.com/stl/create-Heap-by-using-make-heap.aspx
stl make_heap
總結(jié)
以上是生活随笔為你收集整理的stl make_heap_通过使用make_heap()创建堆| C ++ STL的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [转载] 使用DirectInput进行
- 下一篇: [转载] C Primer Plus 第