• multiset [STL]


    View Code
    struct Info{
        int val,key;
        bool friend operator<(Info x,Info y) {
            return x.val>y.val; //定义比较,默认按照val大->小排序
        }
    };
    multiset<int, greater<int> > sbt;
    
    //头文件:#include <set>
    //multiset<int> sbt;         //默认小到大
    //multiset<int, greater<int> > sbt; //定义大到小
    //元素键值允许重复 O(log n)
    //注意 使用前先sbt.clear()
    //sbt.empty()      //判断是否有元素
    //sbt.insert(x)    //插入x元素
    //sbt.erase(x);    //删除x元素
    //sbt.count(x)     //x元素有多少个
    //sbt.begin()       //第一个元素*(sbt.begin())
    //*lower_bound(sbt.begin(),sbt.end(),x) //返回>=x的第一个元素
    // pair<multiset<int>::iterator, multiset<int>::iterator> range;
    //range = sbt.equal_range(x); //返回x的上下界的迭代器
    
    int main() {
        int i,j,k,tmp;
        Info tt;
        sbt.clear();
        for(i=1;i<=10;i++) sbt.insert(rand()-1);
        multiset<int,greater<int> >::iterator it;    //定义迭代器,默认小到大
        for(it=sbt.begin();it!=sbt.end();it++) cout<<(*it)<<" "<<endl;
    //    tmp=*lower_bound(sbt.begin(),sbt.end(),1000);
    //    printf("%d\n", tmp);
        return 0;
    }
  • 相关阅读:
    mybatis(十)缓存
    mybatis(八)复杂查询
    mybatis(六)分页
    mybatis(九)动态SQL
    mybatis(七)只用注解开发
    mybatis(五) 日志
    log4j.properties 相关配置
    mybatis(四)中可能出现的问题
    MyBatis(三) 配置解析
    IIS 发布 .net core 3.1
  • 原文地址:https://www.cnblogs.com/zhang1107/p/3045120.html
Copyright © 2020-2023  润新知