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

    主要功能就是一个堆了 毕竟比手写方便嘛 ( ̄▽ ̄)

    头文件 : include<queue>

    声明:

    priority_queue<int> q; 默认从大到小

    如果想加入自定义的排序顺序的话 有如下几种方式:

    1)

    priority_queue <int,vector<int>,greater<int> > q;
    priority_queue <int,vector<int>,less<int> >q;

    这里不需要vector头文件

    请注意 "…less<int> >… " 的空格 否则会报错

     

    2)

    struct cmp{
        inline bool operator () (const int &x, const int &y){
            return x < y;
        }
    };
    priority_queue<int, vector<int>, cmp> q;

    如是,效果为从大到小排序

     

    3)

    struct node {     

      int w;     
      friend bool operator < (node a, node b)     
      {         
        return a.w < b.w;
      }
    };

    priority_queue<node> q;

    如是,效果为从大到小排序

     

    功能:

    empty()      队列为空返回true

    pop()    删除堆顶元素

    push()        一个元素入堆

    size()      返回元素总个数

    top()     返回堆顶元素

  • 相关阅读:
    JavaScript DOM 编程艺术(第2版)读书笔记(3)
    JavaScript DOM 编程艺术(第2版)读书笔记(1)
    css杂记
    2020年11月15日
    2020年11月14日
    2020年11月13日
    2020年11月12日
    《代码大全》阅读笔记04
    2020年11月11日
    2020年11月10日
  • 原文地址:https://www.cnblogs.com/hjmmm/p/9189180.html
Copyright © 2011-2022 走看看