• set-lower_bound


    ////////////////////////////////////////
    //      2018/04/28 19:23:07
    //      set-lower_bound
    
    // return an iterator to the first element greater than a certain value
    #include <iostream>
    #include <set>
    #include <iomanip>
    #include <string>
    
    using namespace std;
    
    template<class T>
    class Member
    {
    private:
        T first, last;
    public:
        Member(T l) :last(l), first(""){}
        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;
        }
    
        friend bool operator == (const Member& m1, const Member& m2){
            return m1.last == m2.last;
        }
    };
    
    //========================================
    
    int main(){
        typedef Member<string> M;
        typedef set<M, less<M>> S;
    
        S s;
    
        s.insert(M("Smith", "Jhon"));
        s.insert(M("Shevchenko","Taras"));
        s.insert(M("Amstrong","Bill"));
        s.insert(M("Bain","Linda"));
        s.insert(M("Pushkin", "Alexander"));
        s.insert(M("Pasternak","Biris"));
    
        S::iterator it = s.begin();
        while (it != s.end()){
            (it++)->print();
        }
        cout << endl;
    
        M m1("P");
        M m2("Pzz");
    
        S::iterator low = s.lower_bound(m1);
        S::iterator upp = s.upper_bound(m2);
        it = low;
    
        while (it != upp){
            (it++)->print();
        }
    
        return 0;
    }
    
    
    /*
    OUTPUT:
        Bill            Amstrong
        Linda           Bain
        Biris           Pasternak
        Alexander       Pushkin
        Taras           Shevchenko
        Jhon            Smith
    
        Biris           Pasternak
        Alexander       Pushkin
    */ 
  • 相关阅读:
    distributed caching for .net applications
    Linux_18/ mysql
    找到一本不错的Linux电子书,附《Linux就该这么学》章节目录。
    LinuxProbe/ 疑问ABC
    Linux_15/ autofs, DNS
    Linux_14/ SAMBA, NFS
    Linux_13/ 虚拟网站主机功能,Vsftpd
    Linux_12/ Apache, SELinux
    Linux_11/ firewalld-config, SSH, bounding
    Linux_10/ iptables & firewalld
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537904.html
Copyright © 2020-2023  润新知