struct ListNode {
int val;
ListNode *next;
ListNode() : val(0), next(nullptr) {
}
ListNode(int x) : val(x), next(nullptr) {
}
ListNode(int x, ListNode *next) : val(x), next(next) {
}
};
struct cmp{
bool operator()(ListNode *a, ListNode *b){
return a->val > b->val; //是> 而不是<
}
};
int main(){
priority_queue<ListNode *, vector<ListNode *>, cmp> q;//自定义小根堆
priority_queue<int> q;//默认大根堆
priority_queue<int, vector<int>, greater<int>> q;//小根堆
return 0;
}
【c++】priority_queue自定义小根堆
猜你喜欢
转载自blog.csdn.net/SingDanceRapBall/article/details/122588730
今日推荐
周排行