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

    ////////////////////////////////////////
    //      2018/04/25 21:45:11
    //      list-insert
    
    // insert elements into the list
    #include <iostream>
    #include <list>
    #include <algorithm>
    #include <numeric>
    
    using namespace std;
    
    template<class T>
    void print(list<T> l){
        list<T>::iterator it = l.begin();
    
        while (it != l.end()){
            cout << *(it++) << " ";
        }
        cout << endl;
    }
    
    //================================
    int main(){
        list<int> li1(10, 0);
        list<int> li2(5);
        list<int>::iterator it;
    
        iota(li2.begin(), li2.end(), 1);
        cout << "li1:";
        print<int>(li1);
        cout << "li2:";
        print<int>(li2);
    
        it = li1.begin();
        // value of 20 at the pos it
        li1.insert(++it,20);
        cout << "li1:";
        print<int>(li1);
    
        // two value of the 25 at the beginning
        li1.insert(li1.begin(),2,25);
        cout << "li1:";
        print<int>(li1);
    
        // contents of li2 at the end of the li1
        li1.insert(li1.end(),li2.begin(), li2.end());
        cout << "li1:";
        print<int>(li1);
    
        return 0;
    }
    
    /*
    OUTPUT:
        li1:0 0 0 0 0 0 0 0 0 0
        li2:1 2 3 4 5
        li1:0 20 0 0 0 0 0 0 0 0 0
        li1:25 25 0 20 0 0 0 0 0 0 0 0 0
        li1:25 25 0 20 0 0 0 0 0 0 0 0 0 1 2 3 4 5
    */ 
  • 相关阅读:
    距离某天还有多久
    U3D各键值说明
    一些比较重要的函数
    U3D功能脚本备忘
    沟边
    渲染排序
    字符串转整数备录
    沟边
    U3D优化
    Unity中的四个路径
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537961.html
Copyright © 2011-2022 走看看