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
    */ 
  • 相关阅读:
    iOS----------弹窗动画
    书单
    如何屏蔽垃圾短信
    2018年IOS/Android UI设计规范
    关于Keychain
    OpenUDID 和 IDFA 比较
    iOS-----------关于UDID
    iOS-----------设置自定义字体
    【2020Python修炼记】前端开发之 JavaScript 基础
    【2020Python修炼记】前端开发之 CSS基础布局
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537978.html
Copyright © 2011-2022 走看看