Complete the code to insert an element into a min heap using C++ STL.
std::priority_queue<int, std::vector<int>, [1]> minHeap; minHeap.push(10);
To create a min heap in C++, use std::greater<int> as the comparison function.
Complete the code to get the top element from a max heap.
std::priority_queue<int> maxHeap; maxHeap.push(20); int topElement = maxHeap.[1]();
The top() function returns the highest priority element in the heap without removing it.
Fix the error in the code to create a max heap that stores pairs and sorts by the first element.
std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int>>, [1]> pq; pq.push({2, 5});
For a max heap of pairs sorted by the first element, use std::less<std::pair<int, int>> which is the default comparator.
Fill both blanks to create a min heap that stores integers and check if the heap is empty.
std::priority_queue<int, std::vector<int>, [1]> minHeap; if (minHeap.[2]()) { std::cout << "Heap is empty"; }
Use std::greater<int> for min heap and empty() to check if the heap has no elements.
Fill all three blanks to create a max heap of pairs, push a pair, and get the top pair's first element.
std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int>>, [1]> pq; pq.push({3, 7}); int maxFirst = pq.[2]().[3];
Use std::less<std::pair<int, int>> for max heap of pairs, top() to access the top element, and first to get the first value of the pair.