• [STL]弱渣的stl之旅


    FIFO queue:

    先进先出队列:

    #include<queue>
    using namespace std;
    int main()
    {
        queue<int>que;//创造一个队列
        for(int i=1;i<=10;i++)
            que.push(i);//放数
        int t=que.front();//第一个数。
        int t=que.back();//最后一个数。
        int t=que.size();//有几个数
        while(!que.empty())//看是否为空
        {
            que.pop();//踢数
        }
        return 0;
    }

    set:

    集合是按特定顺序存储唯一元素的容器。

    在集合中,元素的值也标识它,并且每个值必须是唯一的。 集合中元素的值不能在容器中修改一次(元素总是const),但可以在容器中插入或删除它们。如果修改这个值的话,就删除这个值,再增加。

     1 #include<set>
     2 using namespace std;
     3 int main()
     4 {
     5     set<int>s;//普通用法创造一个set集合s
     6     //第二种创造方式,直接把数组放进set里
     7     int a[]={1,2,3,4,5};
     8     set<int>s(a,a+5);
     9     //插入数
    10     s.insert(10);
    11     //it迭代器  *it是数
    12     //s.begin() 第一个开始的位置
    13     //s.end() 最后一个位置
    14     set<int>::iterator it;
    15     for(it=s.begin();it!=s.end();it++)
    16         cout<<*it<<endl;
    17     //判断是否为空
    18     while(!s.empty())
    19     {
    20 
    21     }
    22     //有几个数
    23     int t=s.size();
    24     //删除数
    25     s.erase(10);
    26     s.erase(it);
    27     s.erase(it,s.end());
    28     //集合清空
    29     s.clear();
    30     //在集合中找到数的位置
    31     it=s.find(10);
    32     //判断这个数在不在集合里面
    33     if(s.count(10)==0)
    34     {
    35 
    36     }
    37     //二分
    38     it=s.lower_bound(10);//第一个大于等于10的位置
    39     it=s.upper_bound(10);//第一个大于10的位置

    关于二分数组:

        upper_bound(a,a+n,50)-lower_bound(a,a+n,10);

    map:

     1 #include<map>
     2 using namespace std;
     3 int main()
     4 {
     5     map<char,int>m;
     6     map<char,int>::iterator it;
     7     m['b']=100;
     8     m['a']=200;
     9     for(it=m.begin();it!=m.end();it++)
    10         cout<<it->first<<" "<<it->second<<endl;
    11     //map按照第一个first排序
    12     while(!m.empty())
    13     {
    14 
    15     }
    16     int t=m.size();
    17     //map的插入
    18     mp.insert(pair<char,int>('c',300));
    19     it=m.find('a');
    20     m.erase(it);
    21     m.erase(it,m.end());
    22     m.clear();
    23     //这都是第一个first
    24     if(m.count(a)>0)
    25     {
    26 
    27     }
    28     return 0;
    29 }
    No matter how you feel, get up , dress up , show up ,and never give up.
  • 相关阅读:
    leetcode33. Search in Rotated Sorted Array
    pycharm 设置sublime text3 monokai主题
    django class Meta
    leetcode30, Substring With Concatenation Of All Words
    Sublime text3修改tab键为缩进为四个空格,
    sublime text3 python打开图像的问题
    安装上imesupport输入法依然不跟随的解决办法,
    sublime text3 的插件冲突弃用问题,
    sublime text3 BracketHighlighter括号匹配的设置
    windows 下wget的使用
  • 原文地址:https://www.cnblogs.com/Kaike/p/10294860.html
Copyright © 2020-2023  润新知