fork download
  1. // Online C++ compiler to run C++ program online
  2. #include <iostream>
  3. #include <queue>
  4. #include <map>
  5.  
  6. using namespace std;
  7. struct HNode {
  8. int number;
  9. int freq;
  10. bool operator>(const HNode &other) const {
  11. return freq > other.freq;
  12. }
  13. HNode(int number, int freq): number(number), freq(freq) {}
  14. };
  15. int main() {
  16. priority_queue<HNode, vector<HNode>, greater<HNode>> min_heap;
  17. min_heap.push(HNode(1, 10));
  18. min_heap.push(HNode(2, 3));
  19. min_heap.push(HNode(3, 18));
  20. auto &elem = min_heap.top();
  21. cout << elem.number << " " << elem.freq << endl;
  22. return 0;
  23. }
Success #stdin #stdout 0s 5300KB
stdin
Standard input is empty
stdout
2 3