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

    ////////////////////////////////////////
    //      2018/04/29 15:25:15
    //      set-swap
    
    // exchange two sets
    #include <iostream>
    #include <set>
    #include <algorithm>
    #include <iterator>
    
    using namespace std;
    
    void print(set<int, less<int>>& s){
        copy(s.begin(), s.end(), ostream_iterator<int>(cout," "));
        cout << endl;
    }
    //-------------------
    
    int main(){
        int ary1[] = { 1, 2, 3, 2, 3, 4, 8, 2, 5, 6 };
        int ary2[] = { 5, 0, 9, 2, 3, 4, 8, 2, 5, 6 };
    
    
        set<int, less<int>> s1, s2;
    
        s1.insert(ary1, ary1 + 10);
        cout << "s1:";
        print(s1);
    
        s2.insert(ary2,ary2+10);
        cout << "s2:";
        print(s2);
    
        if (s1 != s2){
            s1.swap(s2);
        }else{
            cout << "They are the same!" << endl;
        }
    
        cout << "s1:";
        print(s1);
    
        cout << "s2:";
        print(s2);
    
        return 0;
    }
    
    /*
    OUTPUT:
        s1:1 2 3 4 5 6 8
        s2:0 2 3 4 5 6 8 9
        s1:0 2 3 4 5 6 8 9
        s2:1 2 3 4 5 6 8
    */ 
  • 相关阅读:
    SSH异常
    jquery效果摘要
    js随笔
    html随笔
    demo小样
    SVG图标
    jQuery笔记
    html / css学习笔记-3
    angular 学习笔记
    ng-route使用笔记
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537891.html
Copyright © 2011-2022 走看看