zoukankan      html  css  js  c++  java
  • (优先)队列简单总结

    就总结下写法吧老是忘啊属实dd

    1.队列及相关操作

    1 queue <Type> q;
    1 q.size();//返回q里元素个数
    2 q.empty();//返回q是否为空,空则返回1,否则返回0
    3 q.push(k);//末尾插入k
    4 q.pop();//删掉q的第一个元素
    5 q.top();//返回q的第一个元素 ≈ q.front();
    6 q.back();//返回q的末尾元素

    2.简单优先队列:默认降序队列

    1 priority_queue <Type> q;

    3.自定义优先队列

    先把原型摆上: priority_queue<Type, Container, Functional>

     简单(其实可以归到2里,不过为了对应这个原型还是放到这吧):

    1 //升序队列 
    2 priority_queue <Type,vector<Type>,greater<Type> > q; 
    3 
    4 //降序队列
    5  priority_queue <Type,vector<Type>,less<Type> >q; 

    结构体:

     //(一) 另写比较实现按y降序队列
     struct tmp1 { int x; int y; };
     
     struct tmp2 {
         bool operator() (tmp1 a, tmp1 b) {
             return a.y < b.y; 
         }
     };
     
    priority_queue<tmp1, vector<tmp1>, tmp2> f;
    //(二)直接重载运算符实现按y降序队列
    struct tmp1 {
          int x; int y;
          tmp1(int a,int b) {x = a; y=b;}
          bool operator<(const tmp1& c) const{
              return y < c.y; 
         }
    };
    
    priority_queue<tmp1> d;
  • 相关阅读:
    均匀采样单位圆
    3Sum
    查看SQL语句在SQL Server上的执行时间
    ASP.NET页面请求处理
    原型模式
    ASP.NET页面错误处理
    电子商务推荐位商品模型设计
    HttpModule与HttpHandler使用
    装饰者模式
    ASP.NET编程模型
  • 原文地址:https://www.cnblogs.com/noobimp/p/10325350.html
Copyright © 2011-2022 走看看