当前位置:网站首页>U++ learning note pile
U++ learning note pile
2022-07-02 22:34:00 【It's a bald rabbit】
Heapify
Any existing array can be turned into a heap by calling this function . This is overloaded to accept predicates or not , The non predicate version will use the element type operator<
To determine the sort :
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]
Can pass HeapPush Function to add a new element to the heap , Reorder other nodes to maintain the heap
HeapArr.HeapPush(4);
// HeapArr == [1,2,4,3,4,5,8,10,7,9,6]
The and functions are used to delete the top node from the heap HeapPop
.HeapPopDiscard
The difference between the two is that the former uses a reference to the element type to return a copy of the top element , The latter simply removes the top node without returning it in any way . Both functions make the same changes to the array , And maintain the heap again by reordering other elements appropriately :
int32 TopNode;
HeapArr.HeapPop(TopNode);
// TopNode == 1
// HeapArr == [2,3,4,6,4,5,8,10,7,9]
HeapRemoveAt
An element will be deleted from the array at the given index , Then reorder the elements to maintain the heap :
HeapArr.HeapRemoveAt(1);
// HeapArr == [2,4,4,6,9,5,8,10,7]
Each of these functions , Include Heapify
, You can use optional binary predicates to determine the order of node elements in the heap . By default , Heap operations use element types operator<
To determine the order . When using custom predicates , It is important to use the same predicate for all heap operations .
Last , have access to To check the top node of the heap HeapTop
, Without changing the array :
int32 Top = HeapArr.HeapTop();
// Top == 2
边栏推荐
- Socket socket c/s end process
- 分享一下如何制作专业的手绘电子地图
- New feature of go1.18: introduce new netip Network Library
- Interpretation of CVPR paper | generation of high fidelity fashion models with weak supervision
- Necessary browser plug-ins for network security engineers
- [QT] QT multithreading development - reentrancy and thread safety
- scrcpy这款软件解决了和同事分享手机屏幕的问题| 社区征文
- #include errors detected. Please update your includePath.
- Simpleitk use - 4 Strange question
- Dynamic memory allocation (malloc calloc realloc free)
猜你喜欢
The book "new programmer 002" is officially on the market! From "new database era" to "software defined car"
C语言,实现三子棋小游戏
Utilisation de simpletk - 4. Question étrange
Share how to make professional hand drawn electronic maps
Ransack combined condition search implementation
[shutter] shutter application life cycle (foreground state resumed | background state paused | inactive | component separation state detached)
Daily book CSO advanced road first exposed
The difference between include < > and include ""
Daily book - low code you must understand in the era of digital transformation
Daily book -- analyze the pain points of software automation from simple to deep
随机推荐
Pointer array parameter passing, pointer parameter passing
ServiceMesh主要解决的三大痛点
U++ 学习笔记 堆
Evolution of messaging and streaming systems under the native tide of open source cloud
20220702 how do programmers build knowledge systems?
Etcd raft protocol
Simpleitk use - 4 Strange question
Bridge emqx cloud data to AWS IOT through the public network
Perceptron model and Application
What is it that makes you tremble? Those without fans can learn
将 EMQX Cloud 数据通过公网桥接到 AWS IoT
About test cases
Market Research - current situation and future development trend of marine clutch Market
kubernetes资源对象介绍及常用命令(四)
Market Research - current market situation and future development trend of handheld wound imaging equipment
Task and privilege level protection
【leetcode】1380. Lucky number in matrix
Unity3D学习笔记4——创建Mesh高级接口
Get off work on time! Episode 6 of Excel Collection - how to split and count document amounts
Learn computer knowledge from scratch