mirror of
https://github.com/krahets/hello-algo.git
synced 2026-09-04 14:17:14 +00:00
build
This commit is contained in:
@@ -42,7 +42,15 @@ It's worth mentioning that **since leaf nodes have no children, they naturally f
|
||||
=== "C++"
|
||||
|
||||
```cpp title="my_heap.cpp"
|
||||
[class]{MaxHeap}-[func]{MaxHeap}
|
||||
/* Constructor, build heap based on input list */
|
||||
MaxHeap(vector<int> nums) {
|
||||
// Add all list elements into the heap
|
||||
maxHeap = nums;
|
||||
// Heapify all nodes except leaves
|
||||
for (int i = parent(size() - 1); i >= 0; i--) {
|
||||
siftDown(i);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
=== "Java"
|
||||
|
||||
Reference in New Issue
Block a user