Horje
priority queue ordered by second element Code Example
priority queue ordered by second element
#include <bits/stdc++.h>
using namespace std;

typedef pair<string, int> Max;
struct Compare {
    bool operator()(Max a, Max b) {
        return a.second < b.second;
    }
};

int main() {
    //Max heap custom data type
    priority_queue<Max, vector<Max>, Compare> p;
    p.push(make_pair("a", 1));
    p.push(make_pair("c", 1));
    p.push(make_pair("b", 3));

    while (!p.empty()) {
        Max top = p.top();
        cout << top.first << " => " << top.second << "\n";
        p.pop();
    }
    /*
    * OUTPUT:
    * b = 3
    * a = 1
    * c = 1
    */
}




Cpp

Related
char type casting in c++ Code Example char type casting in c++ Code Example
how to easily trim a str in c++ Code Example how to easily trim a str in c++ Code Example
fatal error: opencv2/opencv.hpp: No such file or directory Code Example fatal error: opencv2/opencv.hpp: No such file or directory Code Example
check variable type c++ Code Example check variable type c++ Code Example
stack implementation using linked list in cpp Code Example stack implementation using linked list in cpp Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
13