zoukankan      html  css  js  c++  java
  • list-erase

    ////////////////////////////////////////
    //      2018/04/25 21:28:52
    //      list-erase
    
    // erase an element
    #include <iostream>
    #include <list>
    #include <algorithm>
    #include <numeric>
    
    using namespace std;
    
    template<class T>
    void print(list<T>& t){
        list<T>::iterator it = t.begin();
        while (it != t.end()){
            cout << *(it++) << " ";
        }
        cout << endl;
    }
    
    //===============================
    
    int main(){
        list<int> li(10);
        iota(li.begin(), li.end(), 1);
        print<int>(li);
    
        list<int>::iterator it;
    
        it = find(li.begin(), li.end(), 6);
        // erase at the pos it
        li.erase(it);
        print<int>(li);
    
        it = find(li.begin(), li.end(), 4);
        // erase form beginning to the pos it
        li.erase(li.begin(), it);
        print<int>(li);
    
        return 0;
    }
    
    
    /*
    OUTPUT:
        1 2 3 4 5 6 7 8 9 10
        1 2 3 4 5 7 8 9 10
        4 5 7 8 9 10
    */ 
  • 相关阅读:
    多条件复合搜索的实现
    mysql字符集统一
    JS控制彈出窗口
    mysql常用sql
    正则表达式
    航班时间
    1月19日
    1月28日check小爱用
    在么小猫
    大连美发备考
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537965.html
Copyright © 2011-2022 走看看