• list-merge


    ////////////////////////////////////////
    //      2018/04/26 8:26:09
    //      list-merge
    
    // merge two lists
    
    #include <iostream>
    #include <list>
    #include <algorithm>
    #include <iterator>
    
    using namespace std;
    
    int main(){
        int ary[] = { 2, 5, 9, 7, 2, 7, 6, 5 };
        list<int> list1(ary, ary + 4);
        list<int> list2(ary + 4, ary + 8);;
    
        cout << "list1:";
        copy(list1.begin(), list1.end(), ostream_iterator<int>(cout, " "));
        cout << endl;
    
        cout << "list2:";
        copy(list2.begin(), list2.end(), ostream_iterator<int>(cout," "));
        cout << endl;
    
        //you have to sort data before mergring it
        list1.sort();
        list2.sort();
    
        list1.merge(list2);
    
        cout << "After"list1.merge(list2)":" << endl;
        cout << "list1:";
        copy(list1.begin(),list1.end(),ostream_iterator<int>(cout," "));
        cout << endl;
        cout << "size of list1 = " << list1.size() << endl;
        cout << "list2:";
        copy(list2.begin(), list2.end(),ostream_iterator<int>(cout," "));
        cout << endl;
        cout << "size of list2 = " << list2.size() << endl;
        return 0;
    }
    
    /*
    OUTPUT:
        list1:2 5 9 7
        list2:2 7 6 5
        After"list1.merge(list2)":
        list1:2 2 5 5 6 7 7 9
        size of list1 = 8
        list2:
        size of list2 = 0
    */
  • 相关阅读:
    js实现分享到QQ
    js 复制粘贴
    js弹窗 js弹出DIV,并使整个页面背景变暗
    PHP实现大转盘抽奖算法
    ext 树节点操作
    ExtJS4图片验证码的实现
    随笔分类
    Oracle、MySql、SQLServer 数据分页查询
    Repeater控件使用(含删除,分页功能)
    SQL compute by 的使用
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537956.html
Copyright © 2020-2023  润新知