-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheapMax.cpp
More file actions
46 lines (35 loc) · 717 Bytes
/
heapMax.cpp
File metadata and controls
46 lines (35 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ulli;
//this code is for such conditions where user gives the input array
void insertHeap(vector<int> &heapArray, int inseKey)
{
if (heapArray.size() == 1)
heapArray.push_back(inseKey);
else
{
heapArray.push_back(inseKey);
int posi = heapArray.size() - 1;
while (heapArray[posi / 2] < heapArray[posi])
{
swap(heapArray[posi], heapArray[posi / 2]);
posi = posi / 2;
}
}
}
int main()
{
int len;
cout << "Write the length of the Heap:";
cin >> len;
vector<int> heapList;
while (len--)
{
int temp;
cin >> temp;
insertHeap(heapList, temp);
}
for (auto q : heapList)
cout << q << " ";
return 0;
}