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
    */ 
  • 相关阅读:
    MSXML 解析XML文件
    内存泄露
    TCHAR CHAR LPTSTR LPCTSTR
    union过代理存根
    jquery placeholder
    SASS 编译后去掉缓存文件和map文件
    js冒泡排序
    android 下滤镜效果的实现
    ViewPagger介绍
    android下实现对wifi连接的监听
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537961.html
Copyright © 2011-2022 走看看