zoukankan      html  css  js  c++  java
  • 顺序容器删除元素 vector list deque

    #include <iostream>
    #include <list>
    #include <algorithm>
    #include <string>

    using namespace std;

    int main()
    {
      list<string> slist;
      slist.push_back("A");
      slist.push_back("B");
      slist.push_back("C");
      slist.push_back("D");
      slist.push_back("E");
      slist.push_back("F");
      slist.push_back("G");

      list<string>::iterator iter;
      for (iter=slist.begin();iter != slist.end();++iter)
      {
        cout << *iter<< endl;
      }

      cout << "---------------------------------------" << endl;

      string s1("D");
      string s2("F");
      list<string>::iterator iter_start = find(slist.begin(),slist.end(),s1);
      list<string>::iterator iter_end = find(slist.begin(), slist.end(), s2);

      if (iter_start != slist.end() && iter_end != slist.end())
      {
        slist.erase(iter_start,iter_end);
      }

      cout << "---------------------------------------" << endl;
      list<string>::iterator iter2;
      for (iter2 = slist.begin(); iter2 != slist.end(); ++iter2)
      {
        cout << *iter2 << endl;
      }
      cout << "---------------------------------------" << endl;


      system("pause");
      return 0;
    }

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

    A
    B
    C
    D
    E
    F
    G
    ---------------------------------------
    ---------------------------------------
    A
    B
    C
    F
    G
    ---------------------------------------
    请按任意键继续. . .

  • 相关阅读:
    bzoj2957 -- 线段树
    bzoj2209 [ JSOI2011 ] -- splay
    bzoj3874 [ AHOI2014 ] -- 爬山算法
    bzoj1038 [ ZJOI2008 ] -- 模拟退火+二分
    bzoj2428 [ HAOI2006 ] -- 模拟退火
    bzoj3680 -- 模拟退火
    bzoj4500 -- 差分约束
    bzoj3527 -- FFT
    bzoj1013 [ JSOI2008 ] -- 高斯消元
    使用nginx try_files 指令 管理静态资源
  • 原文地址:https://www.cnblogs.com/herd/p/10993720.html
Copyright © 2011-2022 走看看