zoukankan      html  css  js  c++  java
  • multiset-find

    ////////////////////////////////////////
    //      2018/04/30 11:36:02
    //      multiset-find
    
    // find a given element
    #include <iostream>
    #include <set>
    #include <iomanip>
    #include <string>
    
    using namespace std;
    
    template<class T>
    class Member
    {
    private:
        T first, last;
    public:
        Member(T l, T f) :last(l), first(f){}
        void print() const{
            cout.setf(ios::left);
            cout << setw(15) << first << " " << last << endl;
        }
    
        friend bool operator <(const Member& m1, const Member& m2){
            return m1.last < m2.last;
        }
    };
    //===================================
    int main(){
        typedef Member<string> M;
        typedef multiset<M, less<M>> S;
        M m("Frost", "Robert");
        S s;
    
        s.insert(m);
        s.insert(M("Smith","John"));
        s.insert(M("Amstrong","Linda"));
        s.insert(M("Bain","Linda"));
    
        S::iterator it = s.begin();
        while (it != s.end()){
            (it++)->print();
        }
        cout << endl;
    
        it = s.find(m);
        if (it == s.end()){
            cout << "element no found!" << endl;
        }
        else{
            cout << "element is found." << endl;
            (*it).print();
        }
    
        return 0;
    }
    
    
    /*
    OUTPUT:
        Linda           Amstrong
        Linda           Bain
        Robert          Frost
        John            Smith
    
        element is found.
        Robert          Frost
    */ 
  • 相关阅读:
    git分支
    git使用
    多人协作
    python初心记录二
    python初心记录一
    Javascript 概念类知识
    想成为前端工程师?希望读完这篇文章能对你有所帮助。
    Egret note
    cocos2d-js 连连看
    PS置入图片之后保留选区方便C图
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537870.html
Copyright © 2011-2022 走看看