小顶堆与大顶堆的自定义cmp函数[已迁移]

1.实验

#include<bits/stdc++.h>
using namespace std;

int main(){
    //auto cmp=[](int a,int b){return a<b;};//3 重定义小于号,即less,是大顶堆,即默认的
    auto cmp=[](int a,int b){return a>b;};//1  //重定义大于号,即greater,是小顶堆
    priority_queue<int,vector<int>,decltype(cmp)> pq(cmp);
    pq.push(1);
    pq.push(2);
    pq.push(3);
    cout<<pq.top();
    return 0;
}

 

posted @ 2021-09-19 15:15  lypbendlf  阅读(205)  评论(0编辑  收藏  举报