0
点赞
收藏
分享

微信扫一扫

C++STL优先队列小根堆大根堆自定义的应用


小根堆 greater

#include<iostream>
#include<queue>
using namespace std;
priority_queue<int, vector<int>, greater<int> >q;
int main(){
q.push(1);
q.push(2);
cout<<q.top();
return 0;
}

大根堆 less

#include<iostream>
#include<queue>
using namespace std;
priority_queue<int, vector<int>, less<int> >q;
int main(){
q.push(1);
q.push(2);
cout<<q.top();
return 0;
}

自定义 struct

#include<iostream>
#include<queue>
using namespace std;
struct node{int x, y;};
struct cmp{
bool operator()(node a, node b){
return a.x > b.x;
}
};
priority_queue<node, vector<node>, cmp>q;
int main(){
return 0;
}


举报

相关推荐

0 条评论