Answers for "stl in heap"

C++
1

heap c++ stl

#include<bits/stdc++.h>
using namespace std;
int main()
{
	vector<int> v1 = {20, 30, 40, 25, 15};
	make_heap(v1.begin(), v1.end());
	cout << "The maximum element of heap is : ";
	cout << v1.front() << endl;
	v1.push_back(50);
	push_heap(v1.begin(), v1.end());
	cout << "The maximum element of heap after push is : ";
	cout << v1.front() << endl;
	pop_heap(v1.begin(), v1.end());
	v1.pop_back();
	cout << "The maximum element of heap after pop is : ";
	cout << v1.front() << endl;
	
	return 0;
}
Posted by: Guest on January-04-2022
3

min heap stl

priority_queue<int, vector<int>, greater<int>> pq;
Posted by: Guest on June-22-2021

Browse Popular Code Answers by Language