We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e4d34b5 commit 4c1023dCopy full SHA for 4c1023d
Maxheapify.cpp
@@ -0,0 +1,27 @@
1
+#include <iostream>
2
+
3
+using namespace std;
4
5
6
+void heapify(int arr[], int n, int i)
7
+{
8
+ int largest = i;
9
+ int l = 2 * i + 1;
10
+ int r = 2 * i + 2;
11
12
13
+ if (l < n && arr[l] > arr[largest])
14
+ largest = l;
15
16
17
+ if (r < n && arr[r] > arr[largest])
18
+ largest = r;
19
20
21
+ if (largest != i) {
22
+ swap(arr[i], arr[largest]);
23
24
25
+ heapify(arr, n, largest);
26
+ }
27
+}
0 commit comments