当前位置:网站首页>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
边栏推荐
- ServiceMesh主要解决的三大痛点
- Daily book - low code you must understand in the era of digital transformation
- Pointer and string
- Destroy in beforedestroy invalid value in localstorage
- Market Research - current situation and future development trend of sickle cell therapy Market
- 关于PHP-数据库的 数据读取,Trying to get property 'num_rows' of non-object?
- Market Research - current situation and future development trend of environmental friendly fireworks Market
- kubernetes资源对象介绍及常用命令(四)
- [shutter] shutter gesture interaction (click event handling | click OnTap | double click | long press | click Cancel | press ontapdown | lift ontapup)
- LandingSite eBand B1冒烟测试用例
猜你喜欢

PIP audit: a powerful security vulnerability scanning tool

Introduction to victoriametrics
![[zero foundation I] Navicat download link](/img/23/e7808884152eeaf186fe756d6adac6.png)
[zero foundation I] Navicat download link
![[shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)](/img/27/8594ba0b49d5008b7469967babed17.jpg)
[shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)

Introduction to the principle of geographical detector
![[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)

C语言,实现三子棋小游戏

Etcd raft protocol

GEE:(二)对影像进行重采样

Image segmentation using pixellib
随机推荐
[shutter] shutter application theme (themedata | dynamic modification theme)
Pointer array parameter passing, pointer parameter passing
Necessary browser plug-ins for network security engineers
Evolution of messaging and streaming systems under the native tide of open source cloud
Perceptron model and Application
Sql service intercepts string
Ransack组合条件搜索实现
[Jianzhi offer] 56 - ii Number of occurrences of numbers in the array II
Kubernetes resource object introduction and common commands (4)
Market Research - current market situation and future development trend of aircraft audio control panel system
GEE:(二)对影像进行重采样
pyqt圖片解碼 編碼後加載圖片
: last child does not take effect
Pip install whl file Error: Error: … Ce n'est pas une roue supportée sur cette plateforme
Market Research - current market situation and future development trend of aircraft wireless intercom system
Official announcement! The golden decade of new programmers and developers was officially released
在beforeDestroy中销毁localStorage中的值无效
Market Research - current market situation and future development trend of intravenous injection (IV) bottles
About test cases
[shutter] shutter gesture interaction (small ball following the movement of fingers)