📌  相关文章
📜  按第二个元素排序的优先级队列 - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:54.784000             🧑  作者: Mango

代码示例1
#include 
using namespace std;

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

int main() {
    //Max heap custom data type
    priority_queue, 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
    */
}