multiset-constructors

////////////////////////////////////////
//      2018/04/29 16:49:12
//      multiset-constructors

#include <iostream>
#include <set>
#include <functional>

using namespace std; 

int main(){
    int ary[] = { 1, 2, 3, 2, 5, 4, 2, 1, 4, 5 };

    multiset<int, less<int>> ms1;
    multiset<int, greater<int>> ms2(ary, ary + 10);

    multiset<int>::iterator it;

    cout << "ms2:";
    for (it = ms2.begin(); it != ms2.end(); it++){
        cout << *it << " ";
    }
    cout << endl;

    //copy constructor
    multiset<int, greater<int>> ms3(ms2);
    cout << "ms3:";
    for (it = ms3.begin(); it != ms3.end(); it++){
        cout << *it << " ";
    }
    cout << endl;

    it = ms2.begin();
    while (it != ms2.end()){
        ms1.insert(*(it++));
    }
    cout << "ms1:";
    for (it = ms1.begin(); it != ms1.end(); it++){
        cout << *it << " ";
    }
    cout << endl;
    return 0;
}


/*
OUTPUT:
    ms2:5 5 4 4 3 2 2 2 1 1
    ms3:5 5 4 4 3 2 2 2 1 1
    ms1:1 1 2 2 2 3 4 4 5 5
*/
posted @ 2018-04-29 17:05  老耗子  阅读(55)  评论(0编辑  收藏  举报