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

    ////////////////////////////////////////
    //      2018/04/27 19:43:54
    //      set-constructors
    #include <iostream>
    #include <set>
    #include <functional>
    
    using namespace std;
    
    int main(){
        int ary[] = { 5, 3, 7, 5, 2, 3, 7, 5, 5, 4 };
        set<int> s1;
        set<int, greater<int>> s2;
    
        for (int i = 0; i < sizeof(ary) / sizeof(int); i++){
            s1.insert(ary[i]);
            s2.insert(ary[i]);
        }
    
        set<int>::iterator it = s1.begin();
        cout << "s1:";
        while (it != s1.end()){
            cout << *(it++) << " ";
        }
        cout << endl;
    
        it = s2.begin();
        cout << "s2:";
        while (it != s2.end()){
            cout << *(it++) << " ";
        }
        cout << endl;
    
        // second from of constructor
        cout << "s3:";
        set<int> s3(ary, ary + 3);
        it = s3.begin();
        while (it != s3.end()){
            cout << *(it++) << " ";
        }
        cout << endl;
    
        // copy constructor (predicate of s1 important)
        set<int, less<int>> s4(s1);
        it = s4.begin();
        cout << "s4:";
        while (it != s4.end()){
            cout << *(it++) << " ";
        }
        cout << endl;
        return 0;
    }
    
    /*
    OUTPUT:
        s1:2 3 4 5 7
        s2:7 5 4 3 2
        s3:3 5 7
        s4:2 3 4 5 7
    */ 
  • 相关阅读:
    房价
    Jsrender初体验
    GCD XOR UVA
    GCD
    Aladdin and the Flying Carpet LightOJ
    HDU6035 2017多校第一场1003 树形DP
    F
    C
    B
    An Easy Physics Problem HDU
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537923.html
Copyright © 2011-2022 走看看