加文

希望是美好的……
随笔 - 0, 文章 - 209, 评论 - 0, 引用 - 0
数据加载中……

list constructor

#include <iostream>
#include <set>
#include <iterator>
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();
    set<int,greater<int>>::iterator It2 = s2.begin();
    cout << "s1 : ";    
    while ( It != s1.end() )
        cout << *(It++) << " ";
    cout << endl;
    cout << "s2 : ";    
    while ( It2 != s2.end() )
        cout << *(It++) << " ";
    cout << endl;
    set<int> s3(ary,ary+3);
    It = s3.begin();
    cout << "s3 : ";    
    while ( It != s3.end() )
        cout << *(It++) << " ";
    cout << endl;
    set<int, less > s4(s1);
    It = s4.begin();
    cout << "s4 : ";
    while ( It != s4.end() )
    cout << *(It++) << " ";
    cout << endl;
    getchar();
    return 0;
}

posted on 2012-04-12 21:24 加文 阅读(117) 评论(0)  编辑 收藏 引用 所属分类: C++


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理