当前位置:网站首页>U++ 学习笔记 堆
U++ 学习笔记 堆
2022-07-02 22:01:00 【是秃头的兔子呀】
Heapify任何现有的数组都可以通过调用该函数变成一个堆。这被重载以接受谓词或不接受谓词,其中非谓词版本将使用元素类型operator<来确定排序:
TArray<int32> HeapArr;
for (int32 Val = 10; Val != 0; --Val)
{
HeapArr.Add(Val);
}
// HeapArr == [10,9,8,7,6,5,4,3,2,1]
HeapArr.Heapify();
// HeapArr == [1,2,4,3,6,5,8,10,7,9]可以通过 HeapPush 函数将新元素添加到堆中,重新排序其他节点以维护堆
HeapArr.HeapPush(4);
// HeapArr == [1,2,4,3,4,5,8,10,7,9,6]和函数用于从堆中删除顶部节点HeapPop。HeapPopDiscard两者的区别在于前者采用对元素类型的引用来返回顶部元素的副本,而后者只是简单地移除顶部节点而不以任何方式返回它。这两个函数都会对数组进行相同的更改,并且通过适当地重新排序其他元素来再次维护堆:
int32 TopNode;
HeapArr.HeapPop(TopNode);
// TopNode == 1
// HeapArr == [2,3,4,6,4,5,8,10,7,9]HeapRemoveAt将从给定索引处的数组中删除一个元素,然后重新排序元素以维护堆:
HeapArr.HeapRemoveAt(1);
// HeapArr == [2,4,4,6,9,5,8,10,7]这些函数中的每一个,包括Heapify,都可以采用可选的二元谓词来确定堆中节点元素的顺序。默认情况下,堆操作使用元素类型operator<来确定顺序。使用自定义谓词时,对所有堆操作使用相同的谓词很重要。
最后,可以使用 来检查堆的顶部节点HeapTop,而无需更改数组:
int32 Top = HeapArr.HeapTop();
// Top == 2
边栏推荐
- [shutter] shutter application life cycle (foreground state resumed | background state paused | inactive | component separation state detached)
- Find objects you can't see! Nankai & Wuhan University & eth proposed sinet for camouflage target detection, and the code has been open source
- CVPR论文解读 | 弱监督的高保真服饰模特生成
- tinymce可视化编辑器增加百度地图插件
- 基于ASP.net的手机销售管理系统(二手手机销售管理系统)+ASP.NET+C#语言+VS2010+数据库可以用于课设、毕设学习
- phpcms实现订单直接支付宝支付功能
- [shutter] shutter page Jump (route | navigator | page close)
- 2019 Nanchang (relive the classic)
- The difference between include < > and include ""
- [shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)
猜你喜欢

An overview of the development of affective computing and understanding research

Daily book - low code you must understand in the era of digital transformation

Sql service intercepts string

Promise optimized callback hell

C language, to achieve three chess games

The failure rate is as high as 80%. What should we do about digital transformation?

《Just because》阅读感受

分享一下如何制作专业的手绘电子地图

Technical solution of vision and manipulator calibration system

Infrastructure is code: a change is coming
随机推荐
Lightgbm principle and its application in astronomical data
Une semaine de vie
Market Research - current situation and future development trend of environmental friendly fireworks Market
Daily book -- analyze the pain points of software automation from simple to deep
Reading experience of just because
Market Research - current situation and future development trend of preclinical medical device testing service market
ServiceMesh主要解决的三大痛点
C language, to achieve three chess games
Record the functions of sharing web pages on wechat, QQ and Weibo
[QT] QT multithreading development - four methods to realize multithreading design
地理探测器原理介绍
TinyMCE visual editor adds Baidu map plug-in
PIP audit: a powerful security vulnerability scanning tool
Market Research - current situation and future development trend of marine clutch Market
Market Research - current market situation and future development trend of genome editing mutation detection kit
The book "new programmer 002" is officially on the market! From "new database era" to "software defined car"
ServiceMesh主要解决的三大痛點
[Jianzhi offer] 57 And are two numbers of S
: last child does not take effect
CVPR论文解读 | 弱监督的高保真服饰模特生成