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

    ////////////////////////////////////////
    //      2018/04/16 15:34:21
    //      vector-erase
    
    #include <iostream>
    #include <vector>
    #include <iterator>
    #include <algorithm>
    
    using namespace std;
    
    int main(){
        vector<int> v(10);
    
        vector<int>::iterator it;
        for (int i = 0; i < 10; i++){
            v[i] = i;
        }
        copy(v.begin(),v.end(), ostream_iterator<int>(cout, " "));
        cout << endl;
    
        // remove first element
        it = v.begin();
        v.erase(it);
        copy(v.begin(), v.end(), ostream_iterator<int>(cout, " "));
        cout << endl;
    
        // remove third element
        it = v.begin()+2;
        v.erase(it);
        copy(v.begin(), v.end(), ostream_iterator<int>(cout, " "));
        cout << endl;
    
        //remove 2 elements from begin to v
        it = v.begin();
        v.erase(it, it + 2);
        copy(v.begin(),v.end(), ostream_iterator<int>(cout, " "));
        cout << endl;
    
        return 0;
    }
    
    /*
    OUTPUT:
        0 1 2 3 4 5 6 7 8 9
        1 2 3 4 5 6 7 8 9
        1 2 4 5 6 7 8 9
        4 5 6 7 8 9
    */ 
  • 相关阅读:
    899. Orderly Queue
    856. Score of Parentheses
    833. Find And Replace in String
    816. Ambiguous Coordinates
    770. Basic Calculator IV
    冒泡排序(Bubble Sort)
    C
    B
    A
    HDOJ-1391
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12538043.html
Copyright © 2011-2022 走看看