Skip to content

Commit 67a363e

Browse files
authored
Create make_heap.md
1 parent 85fadac commit 67a363e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

algorithm/make_heap.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# make_heap
2+
3+
**Description :** make_heap() is used to transform a given sequence into a heap.
4+
A heap is a data structure which points to highest( or lowest) element and making its access in O(1) time.
5+
6+
**Example** :
7+
```cpp
8+
int main() {
9+
int i;
10+
// initializing vector;
11+
vector<int> vi = { 4, 6, 7, 9, 11, 4 };
12+
13+
// using make_heap() to transform vector into
14+
// a max heap
15+
16+
make_heap(vi.begin(),vi.end());
17+
18+
//checking if heap using
19+
// front() function
20+
cout << "The maximum element of heap is : ";
21+
cout << vi.front() << endl;
22+
23+
//printing the heap
24+
for(i=0;i<vi.size();i++){
25+
cout << vi[i] << endl;
26+
}
27+
28+
return 0;
29+
}
30+
```
31+
**[Run Code](https://rextester.com/ZTZW85691)**

0 commit comments

Comments
 (0)