zoukankan      html  css  js  c++  java
  • 更易型算法(Manipulating Algorithms)

    一、移除元素(Removing)元素

    •   remove(iter_begin, iter_end, value) 删除某个区间的元素,但是不会改变该群集的元素数量
    •   coll.erase(remove(coll.begin(),  coll.end(),  value),    coll.end()) 删除区间里的元素,同时会改变元素数量

    注:注意两者的区别

     1 #include <iostream>
     2 #include <list>
     3 #include <algorithm>
     4 #include <iterator>
     5 
     6 using namespace std;
     7 
     8 int main()
     9 {
    10     list<int> coll;
    11     for(int i=1; i < 6; ++i) {
    12     coll.push_back(i);
    13     coll.push_back(i);
    14     }
    15     
    16     copy(coll.begin(), coll.end(),
    17      ostream_iterator<int>(cout, " "));
    18     cout << endl;
    19     
    20     coll.erase(remove(coll.begin(), coll.end(), 3),
    21         coll.end());
    22     copy(coll.begin(), coll.end(),
    23      ostream_iterator<int>(cout, " "));
    24     cout << endl;
    25 }
  • 相关阅读:
    ACM 一种排序
    ACM Binary String Matching
    ACM 括号配对问题
    ACM BUYING FEED
    ACM 喷水装置(二)
    ACM 会场安排问题
    ACM 推桌子
    ACM 心急的C小加
    ACM 田忌赛马
    ACM 疯牛
  • 原文地址:https://www.cnblogs.com/youngkingwang/p/3124939.html
Copyright © 2011-2022 走看看