zoukankan      html  css  js  c++  java
  • 优先队列

    #include <queue>
    using namespace std;
    priority_queue<元素类型[[,底层容器类型],比较器类型]>
    优先队列对象 (构造实参表);
    底层容器:vector/deque(默认)
    优者先出,默认以大者为优,也可以通过比较器定制优先级。
    首------->尾
    50 45 40 30

    #include <iostream>
    #include <queue>
    #include <vector>
    using namespace std;
    class IntCmp {
    public:
    bool operator() (int a, int b) const{
    return a > b;
    }
    };
    class Integer {
    public:
    Integer (int arg) : m_var (arg) {}
    bool operator< (
    Integer const& i) const {
    //    return m_var < i.m_var;
    return m_var > i.m_var;
    }
    friend ostream& operator<< (
    ostream& os, Integer const& i) {
    return os << i.m_var;
    }
    private:
    int m_var;
    };
    int main (void) {
    //    priority_queue<int> pq;
    //    priority_queue<int, vector<int>,
    //    IntCmp> pq;
    priority_queue<Integer> pq;
    pq.push (40);
    pq.push (50);
    pq.push (30);
    pq.push (60);
    pq.push (20);
    pq.push (60);
    pq.push (40);
    while (! pq.empty ()) {
    cout << pq.top () << ' ' <<flush;
    pq.pop ();
    }
    cout << endl;
    return 0;
    }
  • 相关阅读:
    关于Js异常
    gitea windows 安装
    spring boot 错误页面配置
    mysql 常用用函数
    nginx 安装 tomcat pfx 格式证书
    git pull 报错
    maven 打 jar 包,包含 xml, 包含 额外 jar
    git clone 分支代码
    git 切换远程分支
    mycat 在 mysql 8.0 下 无法连接 bug
  • 原文地址:https://www.cnblogs.com/LuckCoder/p/8668468.html
Copyright © 2011-2022 走看看