개요

make_heap

#include <iostream>      
#include <vector>         
#include <algorithm>

using namespace std;

void print(vector<int>& vs)
{
	for (auto v : vs)
		cout << v << ' ';
	cout << endl;
}

int main() {
	vector<int> v( vector<int> {1,6,5,2,3,8,4,9,7 });
	cout << "Before make_heap V \\n";
	print(v);
	cout<<'\\n';

	cout << "After make_heap V \\n";
	make_heap(v.begin(), v.end());
	print(v);

	return 0;
}

push_heap

#include <iostream>       // std::cout
#include <vector>         // std::vector
#include <algorithm>

using namespace std;

void print(vector<int>& vs)
{
	for (auto v : vs)
		cout << v << ' ';
	cout << endl;
}

int main() {
	vector<int> v( vector<int> {1,6,5,2,3,8,4,9,7 });

	make_heap(v.begin(), v.end());
	v.push_back(10);
	//v.push_back(0);
	push_heap(v.begin(),v.end());
	print(v);

	return 0;
}

pop_heap

#include <iostream>       // std::cout
#include <vector>         // std::vector
#include <algorithm>

using namespace std;

void print(vector<int>& vs)
{
	for (auto v : vs)
		cout << v << ' ';
	cout << endl;
}

int main() {
	vector<int> v( vector<int> {1,6,5,2,3,8,4,9,7 });

	make_heap(v.begin(), v.end());
	cout << "before pop :";
	print(v);

	pop_heap(v.begin(),v.end());
	
	cout << "after pop :";
	print(v);

	v.pop_back();
	return 0;
}