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

    默认的优先队列是个极大堆,如果要改变优先队列中元素的优先级,有下面这些方法

    struct cmp1  
    {    
        bool operator ()(int &a,int &b)  
        {    
            return a>b;//最小值优先     
        }    
    };    
    struct cmp2  
    {    
        bool operator ()(int &a,int &b)  
        {    
            return a<b;//最大值优先     
        }    
    };    
    struct node1  
    {    
        int u;    
        bool operator < (const node1 &a) const   
        {    
           return u>a.u;//最小值优先     
        }    
    };    
    struct node2  
    {    
        int u;    
        bool operator < (const node2 &a) const   
        {    
            return u<a.u;//最大值优先     
        }    
    };   
      
    priority_queue<int>q1;//采用默认优先级构造队列       
    priority_queue<int,vector<int>,cmp1>q2;//最小值优先     
    priority_queue<int,vector<int>,cmp2>q3;//最大值优先     
    priority_queue<int,vector<int>,greater<int> >q4;//注意“>>”会被认为错误,     
                                                    //这是右移运算符,所以这里用空格号隔开,最小值优先   
    priority_queue<int,vector<int>,less<int> >q5;//最大值优先      
    priority_queue<node1>q6;  //自定义优先级  
    priority_queue<node2>q7;
  • 相关阅读:
    win10安装mysql5.7.20解压版
    mvn snapshot
    git SSH key
    Grails踩坑记
    oracle数据库中使用hibernate生成表不能正确创建表
    有些人
    制定短期计划(3月9-4.29)
    有些话
    Linux中mysql主从复制
    Linux下安装mysql
  • 原文地址:https://www.cnblogs.com/stranger-/p/7160577.html
Copyright © 2011-2022 走看看