队列//优先出列

#include<queue>
#include<iostream>
#include<string>
using namespace std;
int test[100];
struct cmp{
    bool operator()(int x,int y){
        return test[x]>test[y];
    }
};
struct cmp2{
    bool operator()(string x,string y){
        return x>y;
    }
};
struct node{
    int x, y;
    bool operator<(const node nod){
        return x>nod.x;
    }
};
int main(){
    priority_queue<int,vector<int>,cmp> que1;
    priority_queue<string,vector<string>,cmp2>que2;
    priority_queue<node>que3;
    return 0;
}

1.在优先队列中存储常用类型时,利用自定义结构体cmp来实现自定义的<比较。 

2.在优先队列中存储自定义数据类型时,只需要在自定义类型中重载<比较。

转自  传送

猜你喜欢

转载自blog.csdn.net/zzzanj/article/details/80979526