中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

C++ STL Set 快速入門

2018-07-20    來源:open-open

容器云強(qiáng)勢上線!快速搭建集群,上萬Linux鏡像隨意使用

Set

一 、簡介

set是一個集合,其中元素有序,排序的方式按照指定的方式來排序,不指定則默認(rèn)按照升序排列
set中元素不可以相同;比較兩個set相同,他們的排序方式和元素都要相同;不能直接改變元素的值,需要先刪除,再插入。

set經(jīng)常用來保存一組數(shù)據(jù),他們獲得和使用的順序無關(guān)緊要,只需要考慮是否是在集合中即可。

二 、示例代碼

    #include <iostream>  
    #include <iterator>  
    #include <algorithm>  
    #include <set>  
    using namespace std;  
    struct classcomp     
    {    
        bool operator()(const char& lhs,const char& rhs)    
        {    
            return lhs > rhs;    
        }    
    };   
    char array[] = {'e','f','g'};  
    int _tmain(int argc, _TCHAR* argv[])  
    {  
        set<char,classcomp> myset;  
        myset.insert('a');  
        myset.insert('b');  
        myset.insert('c');  
        copy(myset.begin(),myset.end(),ostream_iterator<char>(cout," "));  
        cout<<endl;  
        cout<<myset.insert('d').second<<endl;  
        //Now a b c d  
          
        myset.insert(array,array+3);  
        copy(myset.begin(),myset.end(),ostream_iterator<char>(cout," "));  
        cout<<endl;  
        //Now g f e d c b a  
        myset.erase('d');  
        //Now g f e c b a  
        myset.erase(myset.begin());  
        //Now f e c b a   
        copy(myset.begin(),myset.end(),ostream_iterator<char>(cout," "));  
        cout<<endl;  
        //myset.clear();//清空set  
        set<char,classcomp>::iterator it= myset.begin();  
        if ((it = myset.find('k')) == myset.end())  
        {  
            cout<<"Can not find K in this set"<<endl;  
        }  
        cout<<"Current size is :"<<myset.size()<<endl;  
    }  

標(biāo)簽: 代碼

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:android中文件操作

下一篇: android中WebView調(diào)用js