日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

stl make_heap_通过使用make_heap()创建堆| C ++ STL

發(fā)布時間:2025/3/11 编程问答 14 豆豆
生活随笔 收集整理的這篇文章主要介紹了 stl make_heap_通过使用make_heap()创建堆| C ++ STL 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。