zoukankan      html  css  js  c++  java
  • set-upper_bound

    ////////////////////////////////////////
    //      2018/04/29 15:33:59
    //      set-upper_bound
    
    // returns 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","John"));
        s.insert(M("Shevchenko","Taras"));
        s.insert(M("Amstrong","Bill"));
        s.insert(M("Bain","Linda"));
        s.insert(M("Pushkin","Alexander"));
        s.insert(M("Pasternak","Boris"));
    
        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();
        }
        cout << endl;
    
        return 0;
    }
    
    
    /*
    OUTPUT:
        Bill            Amstrong
        Linda           Bain
        Boris           Pasternak
        Alexander       Pushkin
        Taras           Shevchenko
        John            Smith
    
        Boris           Pasternak
        Alexander       Pushkin
    */ 
  • 相关阅读:
    C#多线程学习
    什么是启发式算法(转)
    进程与线程的一个简单解释
    Fedora19/18/17安装显卡驱动和无限网卡驱动
    MySQL性能优化的最佳20+条经验
    npm使用笔记
    函数式编程--curry化
    读js语言精粹收获
    如何解决mysql数据注入网站时中文字符显示问号
    如何实现区域内横向滚动条?
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537888.html
Copyright © 2011-2022 走看看