본문 바로가기
C and C++/C and C++ Examples

[Example Codes]make_heap(v.begin(), v.end()), v.push_back(), push_heap(v.begin(), v.end()), pop_heap(v.begin(), v.end())

by Henry Cho 2020. 4. 30.
728x90

make_heap(v.begin(), v.end()), v.push_back(), push_heap(v.begin(), v.end()), pop_heap(v.begin(), v.end())


// WhoisHOO
// C++에 빠지다
// Example Codes of Heap

#include<iostream> 
#include<algorithm>
#include<vector> 
using namespace std;

int main()
{ 
	vector<int> v = { 5,8,10,95,1,87,85,49 };
 
	make_heap(v.begin(), v.end());
	v.push_back(26);
	push_heap(v.begin(), v.end());
	v.push_back(28);
	push_heap(v.begin(), v.end());
	pop_heap(v.begin(), v.end());
	v.pop_back();
	pop_heap(v.begin(), v.end());
	v.pop_back();

	cout << "{ ";
	for (int &x : v)
	{
		cout << x << ", ";
	}
	cout << "}" << endl;

	return 0;
}
{ 85, 49, 10, 26, 28, 8, 1, 5, }

예제 코드를 활용하는 방법!!

1. 예제 코드를 보고 컴파일.

2. 예제 코드에서 모르는 부분 댓글!

3. Flowcharts를 직접 그려보기.

 

 

728x90

댓글