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:
  1. Access the top element of the priority queue:
int topElement =;
  1. Remove the top element from the priority queue: