priority queue using heap

  1. Include the necessary header file:
#include <queue>
  1. Define the comparator function or use the default comparator:
bool compare(int a, int b) {
    return a < b; // Replace with custom comparison logic
}
  1. Declare the priority queue with the specified element type and comparator:
std::priority_queue<int, std::vector<int>, decltype(&compare)> pq(&compare);
  1. Insert elements into the priority queue:
pq.push(5);
pq.push(10);
pq.push(3);
  1. Access the top element of the priority queue:
int topElement = pq.top();
  1. Remove the top element from the priority queue:
pq.pop();