2018-01-28 C++set的使用

1、定义和初始化

set<int> S;
set<int> S(S1);
vector<int> ivec({0,1,2,3,4,5,5,4,3,2,1,0});
set<int> S(ivec.iter1, ivec.iter2);

定义一个集合S,分别为:不初始化,用集合S1初始化,用迭代器初始化。
2、set的插入,只能使用insert函数插入。

S.insert(2);

3、set的查找和读取元素
使用find()函数返回的下标, count()函数返回共有多少个。

S.find(4);
S.count(5);

4、set中删除元素

S.erase(3);
S.erase(S.begin());
S.erase(S.begin(), S.end());
    原文作者:alexssssu
    原文地址: https://www.jianshu.com/p/4f981e1f7e55
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞