• c++ set multiset


    #include <iostream>
    #include <set>

    using namespace std;

    template<typename Container>
    void PrintContents(const Container& con);

    template<typename Container>
    void PrintContents(const Container& con)
    {
      Container::const_iterator iter = con.begin();
      while (iter != con.end())
      {
        cout << *iter << " ";
        ++iter;
      }
      cout << endl;
    }

    int main()
    {
      set<int> set1;
      multiset<int> multiset1;

      set1.insert(10);
      set1.insert(20);
      set1.insert(30);
      set1.insert(20);

      cout << "size:" << set1.size() << endl;
      set<int>::const_iterator set_iter1 = set1.begin();
      while (set_iter1 != set1.end())
      {
        cout << *set_iter1 << " ";
        set_iter1++;
      }
      cout << endl;
      
      multiset1.insert(set1.begin(),set1.end());
      multiset1.insert(50);
      multiset1.insert(50);

      cout << "--------------------------------------------" << endl;
      cout << "multiset size:" << multiset1.size() << " " << multiset1.count(50) << endl;

      multiset<int>::const_iterator multiset_iter1 = multiset1.begin();
      while (multiset_iter1 != multiset1.end())
      {
        cout << *multiset_iter1 << " ";
        multiset_iter1++;
      }
      cout << endl;
      cout << "------------------------------------------- - " << endl;
      
      PrintContents(multiset1);

      cout << "------------------------------------------- - " << endl;
      set<int>::iterator iter_f = set1.find(20);
      if (iter_f != set1.end())
      {
        cout << "find: "<<*iter_f << endl;
      }
      else
      {
        cout << "not find:" << endl;
      }

      multiset1.erase(50);
      PrintContents(multiset1);

      system("pause");
      return 0;
    }

    =======================================================

    size:3
    10 20 30
    --------------------------------------------
    multiset size:5 2
    10 20 30 50 50
    ------------------------------------------- -
    10 20 30 50 50
    ------------------------------------------- -
    find: 20
    10 20 30
    请按任意键继续. . .

  • 相关阅读:
    怎样开始学日语
    转 送给日语初学者的寄语
    分享一个flash播放音乐的类
    日语网址
    北京奥运会门票价格一览表
    上班防沉迷系统
    ActionScript 3.0 概要
    Actionscript 3学习资源
    客户导入后需要Update的字段
    ORA01219
  • 原文地址:https://www.cnblogs.com/herd/p/10997706.html
Copyright © 2020-2023  润新知