当前位置:网站首页>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
边栏推荐
- 关于PHP-数据库的 数据读取,Trying to get property 'num_rows' of non-object?
- *C language final course design * -- address book management system (complete project + source code + detailed notes)
- 地理探测器原理介绍
- What "real skills" should a million year old cloud native developer master? Alibaba, Tencent, meituan and byte decrypt together
- Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?
- VIM command-t plugin error: unable to load the C extension - VIM command-t plugin error: could not load the C extension
- Market Research - current situation and future development trend of sickle cell therapy Market
- Find objects you can't see! Nankai & Wuhan University & eth proposed sinet for camouflage target detection, and the code has been open source
- [001] [arm-cortex-m3/4] internal register
- 100 important knowledge points that SQL must master: using cursors
猜你喜欢

What "real skills" should a million year old cloud native developer master? Alibaba, Tencent, meituan and byte decrypt together

phpcms实现订单直接支付宝支付功能

图像基础概念与YUV/RGB深入理解

About test cases
![[staff] Sibelius 7.5.1 score software installation (software download | software installation)](/img/1a/4932a7931c54248c065cf8a1462d34.jpg)
[staff] Sibelius 7.5.1 score software installation (software download | software installation)

What is it that makes you tremble? Those without fans can learn

The source code of the daily book analyzes the design idea of Flink and solves the problems in Flink

Official announcement! The golden decade of new programmers and developers was officially released

《Just because》阅读感受

Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?
随机推荐
The source code of the daily book analyzes the design idea of Flink and solves the problems in Flink
C语言,实现三子棋小游戏
Five message formats of OSPF
Find objects you can't see! Nankai & Wuhan University & eth proposed sinet for camouflage target detection, and the code has been open source
Market Research - current situation and future development trend of marine clutch Market
C language, to achieve three chess games
Destroy in beforedestroy invalid value in localstorage
SQL必需掌握的100个重要知识点:管理事务处理
Unity3d learning notes 4 - create mesh advanced interface
How do I access the kubernetes API?
Daily book - low code you must understand in the era of digital transformation
图像基础概念与YUV/RGB深入理解
scrcpy这款软件解决了和同事分享手机屏幕的问题| 社区征文
Necessary browser plug-ins for network security engineers
New feature of go1.18: trylock, which has been tossed n times
Technical solution of vision and manipulator calibration system
Daily book CSO advanced road first exposed
[leetcode] sword finger offer 11 Rotate the minimum number of the array
Official announcement! The golden decade of new programmers and developers was officially released
[staff] Sibelius 7.5.1 score software installation (software download | software installation)