fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. template<typename T>
  5. class custom_priority_queue_MinHeap : public std::priority_queue<T, std::vector<T>>
  6. {
  7. public:
  8. bool remove(const T& value)
  9. {
  10. auto it = std::find(this->c.begin(), this->c.end(), value);
  11. if (it != this->c.end())
  12. {
  13. this->c.erase(it);
  14. std::make_heap(this->c.begin(), this->c.end(), this->comp);
  15. return true;
  16. }
  17.  
  18. return false;
  19. }
  20.  
  21. bool operator()(const pair<int, int> &a, const pair<int, int> &b)
  22. {
  23. cout << "Custom comparator called" << endl;
  24. return a.second > b.second;
  25. }
  26. };
  27.  
  28. int main() {
  29. custom_priority_queue_MinHeap<pair<int, int>> minHeap;
  30. minHeap.push({0, 10});
  31. minHeap.push({1, 5});
  32. minHeap.push({2, 15});
  33.  
  34. while(!minHeap.empty())
  35. {
  36. pair<int, int> p = minHeap.top();
  37. minHeap.pop();
  38. cout << p.first << " " << p.second << endl;
  39. }
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0s 4360KB
stdin
Standard input is empty
stdout
2 15
1 5
0 10