Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bad6013

Browse files
author
zhunago
committed
make push and pop heap in C++
1 parent e483537 commit bad6013

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

‎algorithm/heap.cpp‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <algorithm>
2+
#include <iostream>
3+
#include <vector>
4+
5+
using namespace std;
6+
7+
int main(void)
8+
{
9+
vector<int> input = {23, 1, 243, 2, 342, 3, 23, 43, 54};
10+
make_heap(input.begin(), input.end(), greater<int>());
11+
for(int i : input)
12+
{
13+
cout << i << " ";
14+
}
15+
cout << endl;
16+
17+
input.push_back(0);
18+
push_heap(input.begin(), input.end(), greater<int> ());
19+
int a = input[0];
20+
cout << a << endl;
21+
22+
pop_heap(input.begin(), input.end(), greater<int> ());
23+
input.pop_back();
24+
a = input[0];
25+
cout << a << endl;
26+
a = input.back();
27+
cout << a << endl;
28+
29+
return 0;
30+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /