• 学习set容器


      1 # include<iostream>
      2 # include<cstdio>
      3 # include<set>
      4 using namespace std;
      5 struct myComp
      6 {
      7     bool operator()(const int &a,const int &b)
      8     {
      9         if(a!=b)
     10             return a>b;
     11         else
     12             return a<b;
     13     }
     14 };
     15 struct Info
     16 {
     17     string name;
     18     float score;
     19     bool operator < (const Info &a)const
     20     {
     21         return a.score < score;
     22     }
     23 };
     24 int main(int argc,const char * argv[])
     25 {
     26     /*---------------------------------------------*/
     27     //本部分insert,实现有序和去重
     28     //set<int>s;
     29     //s.insert(8);
     30     //s.insert(1);
     31     //s.insert(12);
     32     //s.insert(6);
     33     //s.insert(8);
     34 
     35     //set<int>::iterator it;
     36     //for(it = s.begin();it!=s.end();it++)
     37     //{
     38     //    cout<<*it<<endl;
     39     //}
     40 
     41     /*----------------------------------------------*/
     42     //reverse
     43     //set<int>s;
     44     //s.insert(8);
     45     //s.insert(1);
     46     //s.insert(12);
     47     //s.insert(6);
     48     //s.insert(8);
     49 
     50     //set<int>::reverse_iterator rit;
     51     //for(rit = s.rbegin();rit!=s.rend();rit++)
     52     //{
     53     //    cout<<*rit<<endl;
     54     //}
     55 
     56     /*-----------------------------------------------*/
     57     //erase
     58     //set<int>s;
     59     //s.insert(8);
     60     //s.insert(1);
     61     //s.insert(12);
     62     //s.insert(6);
     63     //s.insert(8);
     64 
     65     //s.erase(6);
     66     //set<int>::reverse_iterator rit;
     67     //for(rit = s.rbegin(); rit!=s.rend(); rit++)
     68     //{
     69     //    cout<<*rit<<endl;
     70     //}
     71     //s.clear();
     72     //cout<<s.size()<<endl;
     73 
     74 
     75     /*-------------------------------------------*/
     76     //元素的检索
     77     //set<int>s;
     78     //s.insert(8);
     79     //s.insert(1);
     80     //s.insert(12);
     81     //s.insert(6);
     82     //s.insert(8);
     83 
     84 
     85     //set<int>::iterator it;
     86 
     87     //it = s.find(6);
     88     //if(it!=s.end())
     89     //   cout<<*it<<endl;
     90     //else
     91     //    cout<<"not find it"<<endl;
     92     //it = s.find(20);
     93     //if(it!=s.end())
     94     //    cout<<*it<<endl;
     95     //else
     96     //    cout<<"not find it"<<endl;
     97 
     98     /*---------------------------------------*/
     99     //自定义比较函数
    100     //set<int,myComp>s;
    101     //s.insert(8);
    102     //s.insert(1);
    103     //s.insert(12);
    104     //s.insert(6);
    105     //s.insert(8);
    106     //set<int,myComp>::iterator it;
    107     //for(it = s.begin(); it!=s.end(); it++)
    108     //{
    109     //    cout<<*it<<endl;
    110     //}
    111 
    112     /*-----------------------------------------*/
    113     //另一种自定义比较
    114     //set<Info>s;
    115     //Info info;
    116     //info.name = "Jack";
    117     //info.score = 20.5;
    118     //s.insert(info);
    119     //info.name = "Nacy";
    120     //info.score = 60.5;
    121     //s.insert(info);
    122     //set<Info>::iterator it;
    123     //for(it = s.begin();it!=s.end();it++)
    124     //{
    125     //    cout<<(*it).name<<":"<<(*it).score<<endl;
    126     //}
    127 
    128 
    129 }
    View Code
  • 相关阅读:
    常用正则表达式
    在过滤器中设置一个应用范围内的路径
    在过滤器中设置一个应用范围内的路径
    shell編程之遠程開啓多個機器的ElasticSearch
    shell之CMD的使用,是用` `還是" "?
    shell編程之自動化集群搭建並啓動
    shell編程之權限
    登录用户出现‘’-bash-4.2$‘’的问题解决
    locate: can not open `/var/lib/mlocate/mlocate.db': No such file or directory
    Spring之mvc應用(包含aop)
  • 原文地址:https://www.cnblogs.com/sxmcACM/p/3460191.html
Copyright © 2020-2023  润新知