• STL之priority_queue


    下面以 long long 型队列介绍:
    
    Q.empty()   // 判断队列是否为空 返回ture表示空 返回false表示空      bool
    Q.top()     // 返回顶端元素的值  元素还在队列里                     long long 
    Q.pop()     // 删除顶端元素                                         void
    Q.push(V)   // 把 long long型的数V加入到队列里 它会制动条件V的位置  void
    Q.size()    // 返回队列里元素个数                                   unsigned int
    
    
    priority_queue<int,vector<int>,greater<int> > que;  // 最小优先队列 
    priority_queue<int> que1;                           // 最大优先队列
    priority_queue<int,vector<int>,less<int> > que1;   //  最大优先队列  ( 注意在两个尖括号之间一定要留空格。)
    priority_queue<node>que;                          // 结构体node自己定义
    
    
    是其它类型的如long long 用最小优先队列需要从载 cmp 类
     
    struct cmp{  // 整形最小优先队列
       bool operator()(const int i,const int j){
            return i>j;
       } 
    };
    priority_queue<int,vector<int>,cmp>que;  
    
    
    struct cmp{ // long long 型最小优先队列
        bool operator()(const long long i,const long long j){
            return i>j;
        }
    };
    priority_queue<int,vector<long long>,cmp> Q;
    
    
    
    struct cmp{  // string表示整数最小最优队列的重载
       bool operator()(const string &i,const string &j){
           int len1=i.length(),len2=j.length();
           if(len1==len2)return i.compare(j)>0;
           return len1>len2;
       }
    };
    priority_queue<int,vector<string>,cmp> Q;
    
    
    bool cmpe(string i,string j){ // 从大数到小数的排序重载
         int len1=i.length(),len2=j.length();
         if(len1==len2)return i.compare(j)>0;
         return len1 > len2;
    }
    sort(a+1,a+10+1,cmpe);
  • 相关阅读:
    解释器
    桥接
    组合
    hbase读性能优化
    Hbase为什么写比读快
    http和https区别
    R apply() 函数和 tapply() 函数
    R 语言 decostand() 函数
    R多行交叉作图
    k-mean 拐点
  • 原文地址:https://www.cnblogs.com/kane0526/p/4316295.html
Copyright © 2020-2023  润新知