construct Set && Multiset

作者在 2008-08-17 14:24:07 发布以下内容
//set
//multiset's constructor is as same as the set
#include<iostream>
#include<set>
using namespace std;
int main(void)
{
   
set<int>::iterator Iter;
    //set<int>::iterator s1_Iter,s2_Iter,s3_Iter,s4_Iter,s5_Iter,s6_Iter;
   
set<int> s0;   //create an empty set s0 of key type integer
   
set<int,less<int> > s1;  //create dn empty set s1 with the key comparison function of less than.
   
s1.insert(10), s1.insert(20), s1.insert(30), s1.insert(40);
    set<int,greater<int> > s2; //
   
s2.insert(10), s2.insert(20),s2.insert(30), s1.insert(40);
    set<int>::allocator_type s1_Alloc;  //
   
s1_Alloc = s1.get_allocator();
    set<int> s3(less<int>(),s1_Alloc);  //create a set s3 with the allocator of set s1
   
s3.insert(30);
    set<int> s4(s1);    //create a copy,set s4 of set s1
   
set<int>::const_iterator s1_bcIter,s1_ecIter;
    s1_bcIter = s1.begin(), s1_ecIter = s1.begin();
    s1_ecIter++, s1_ecIter++;
    set<int> s5(s1_bcIter,s1_ecIter);   //create a set s5 by copying the range s1(_First,_Last)
   
set<int>::allocator_type s2_Alloc;
    s2_Alloc = s2.get_allocator();
    //create a set s6 by copying the range of s4(_First,_Last)and with the allocator of set s2
   
set<int> s6(s4.begin(),++s4.begin(),less<int>(),s2_Alloc);
    cout<<"output (s1-s6),take one line for each set"<<endl;
    for (Iter = s1.begin(); Iter != s1.end();Iter++) cout<<*Iter<<" ";
    cout<<endl;
    for (Iter = s2.begin(); Iter != s2.end();Iter++) cout<<*Iter<<" ";
    cout<<endl;
    for (Iter = s3.begin(); Iter != s3.end();Iter++) cout<<*Iter<<" ";
    cout<<endl;
    for (Iter = s4.begin(); Iter != s4.end();Iter++) cout<<*Iter<<" ";
    cout<<endl;
    for (Iter = s5.begin(); Iter != s5.end();Iter++) cout<<*Iter<<" ";
    cout<<endl;
    for (Iter = s6.begin(); Iter != s6.end();Iter++) cout<<*Iter<<" ";
    cout<<endl;
    return 0;
}
STL | 阅读 5014 次
文章评论,共0条
游客请输入验证码
浏览56002次
最新评论