034day(set的学习)

来源:互联网 发布:在线直播网站源码 编辑:程序博客网 时间:2024/06/05 04:28

172210704111-陈国佳总结《2017年11月13日》【连续034天】

标题:set的学习;

内容:A.观看MOOC12.5,13.1;

B.(a).set:

set和multiset的区别在于容器里不能有重复元素;

a和b重复<=> “a必须排在b前面”和“b必须排在a前面”都不成立;

set插入元素可能不成功;

pair模板:

pair<T1,T2>等价于struct{T1 first;T2 second;}; 

        set<int> st;

int a[10]={1,2,3,8,7,7,5,6,8,12};
for(int i=0;i<10;++i)
     st.insert(a[i]);
cout<<st.size()<<endl;
set<int>::iterator i;
for(i =st.begin();i !=st.end();++i)
  cout<<*i<<" ";
cout<<endl;
pair<set<int>::iterator,bool>result=st.insert(2);
//当插入元素成功时,first会指向新插入的元素,并且second为ture,否则,first指向set中原有的元素,second为false
if(!result.second)
      cout<<*result.first<<" already exists."<<endl;
else
     cout<<*result.first<<" inserted."<<endl;  


(b)multimap和map


明日计划:练习枚举;