multiset-insert

////////////////////////////////////////
//      2018/04/30 11:45:49
//      multiset-insert

// insert element into the multiset

#include <iostream>
#include <set>

using namespace std;

void print(multiset<int, less<int>>& s){
    multiset<int, less<int>>::iterator it;
    for (it = s.begin(); it != s.end(); it++){
        cout << *it << " ";
    }
    cout << endl;
}

//===============================
int main(){
    int ary[] = { 1, 2, 3, 2, 3, 4, 8, 2, 5, 6 };
    multiset<int, less<int>> s;

    s.insert(ary, ary + 10);
    print(s);

    s.insert(ary, ary + 5);
    print(s);

    multiset<int, less<int>>::iterator it = s.begin();
    s.insert(it, 20);
    print(s);

    return 0;
}


/*
OUTPUT:
    1 2 2 2 3 3 4 5 6 8
    1 1 2 2 2 2 2 3 3 3 3 4 5 6 8
    1 1 2 2 2 2 2 3 3 3 3 4 5 6 8 20
*/
posted @ 2018-04-30 12:22  老耗子  阅读(42)  评论(0编辑  收藏  举报