zoukankan      html  css  js  c++  java
  • deque-swap

    ////////////////////////////////////////
    //      2018/04/25 14:38:32
    //      deque-swap
    #include <iostream>
    #include <deque>
    #include <algorithm>
    
    using namespace std;
    
    template<class T>
    class Print
    {
    public:
        void operator()(T& t){
            cout << t << " ";
        }
    
    };
    //==========================
    
    int main(){
        int ary[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
        Print<int> print;
        deque<int> d1(ary, ary + 7);
        deque<int> d2(ary + 7, ary + 10);
    
        cout << "Deque d1:" << endl;
        for_each(d1.begin(),d1.end(),print);
        cout << endl;
        cout << "Szie of d1 = " << d1.size() << endl;
    
        cout << "Deque d2:" << endl;
        for_each(d2.begin(),d2.end(),print);
        cout << endl;
        cout << "Size of d2 = " << d2.size() << endl;
    
    
        d1.swap(d2);
        cout << "After swapping:" << endl;
    
        cout << "Deque d1:" << endl;
        for_each(d1.begin(), d1.end(), print);
        cout << endl;
        cout << "Size of d1 = " << d1.size() << endl;
    
        cout << "Deque d2:" << endl;
        for_each(d2.begin(),d2.end(),print);
        cout << endl;
        cout << "Size of d2 = " << d2.size() << endl;
    
        return 0;
    }
    
    
    /*
    OUTPUT:
        Deque d1:
        1 2 3 4 5 6 7
        Szie of d1 = 7
        Deque d2:
        8 9 10
        Size of d2 = 3
        After swapping:
        Deque d1:
        8 9 10
        Size of d1 = 3
        Deque d2:
        1 2 3 4 5 6 7
        Size of d2 = 7
    */ 
  • 相关阅读:
    Android获取手机内存和sd卡相关信息
    总结(创建快捷方式等)
    正则是个好东西
    Android自定义AlertDialog
    Eclipse生成author等注释
    day18 io多路复用
    json 模块
    re 模块
    random 模块
    hashlib 模块
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537978.html
Copyright © 2011-2022 走看看