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

    ////////////////////////////////////////
    //      2018/04/29 8:43:34
    //      set-rend
    
    // returns a reverse iterator to the begining of the set
    #include <iostream>
    #include <set>
    #include <iomanip>
    #include <string>
    
    using namespace std;
    
    template<class T>
    class Member{
    private:
        T first, last;
    public:
        Member(T f, T l) :first(f), last(l){}
        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 set<M, less<M>> S;
        S s;
    
        M m("Frost","Robert");
        s.insert(m);
        s.insert(M("Smith","John"));
        s.insert(M("Amstrong","Bill"));
        s.insert(M("Bain","Linda"));
    
    
        S::iterator it = s.begin();
        while (it != s.end()){
            (it++)->print();
        }
        cout << endl;
    
        S::reverse_iterator rl = s.rbegin();
        while (rl != s.rend()){
            (rl++)->print();
        }
        cout << endl;
    
        return 0;
    }
    
    
    /*
    OUTPUT:
        Amstrong        Bill
        Smith           John
        Bain            Linda
        Frost           Robert
    
        Frost           Robert
        Bain            Linda
        Smith           John
        Amstrong        Bill
    
    */
  • 相关阅读:
    【SpringBoot框架学习】yml/yaml语法 详解
    【SpringBoot框架学习】搭建开发环境 详解
    【SpringBoot框架学习】热部署 的配置 详解
    JVM-类加载机制
    JVM-字节码
    JVM-垃圾收集
    JVM-体系结构
    HTTP-报文结构
    TCP-四次挥手
    TCP-三次握手
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537896.html
Copyright © 2011-2022 走看看