zoukankan      html  css  js  c++  java
  • deque-rbegin and rend

    ////////////////////////////////////////
    //      2018/04/25 7:20:33
    //      deque-rbegin and rend
    
    #include <iostream>
    #include <iomanip>
    #include <deque>
    #include <string>
    #include <iterator>
    #include <algorithm>
    
    using namespace std;
    
    class ID{
    private:
        string name;
        int score;
    public:
        ID(string name, int score) :name(name), score(score){};
        friend bool operator <(const ID &, const ID &);
        void display(){
            cout.setf(ios::left);
            cout << setw(3) << score << name << endl;
        }
    };
    
    //------------------------------------
    // comperation function for sorting
    bool operator < (const ID& a, const ID& b){
        return a.score < b.score;
    }
    
    typedef deque<ID> Deque;
    int main(){
        Deque d;
        Deque::iterator iter;
        d.push_back(ID("Smith A", 96));
        d.push_back(ID("Amstrong B.", 91));
        d.push_back(ID("Watson D", 82));
        for (iter = d.begin(); iter != d.end(); iter++){
            iter->display();
        }
    
        sort(d.begin(), d.end());
    
        cout << endl << "Sorted by Score " << endl;
        cout << "==================" << endl;
        for (iter = d.begin(); iter != d.end(); iter++){
            iter->display();
        }
    
        cout << endl << "Reverse output" << endl;
        cout << "==================" << endl;
    
        Deque::reverse_iterator r = d.rbegin();
        while (r != d.rend()){
            (r++)->display();
        }
        cout << endl;
        return 0;
    }
    
    
    /*
    OUTPUT:
        96 Smith A
        91 Amstrong B.
        82 Watson D
    
        Sorted by Score
        ==================
        82 Watson D
        91 Amstrong B.
        96 Smith A
    
        Reverse output
        ==================
        96 Smith A
        91 Amstrong B.
        82 Watson D
    */ 
  • 相关阅读:
    正则表达式
    Ajax跨域问题---jsonp
    Ajax
    字符串总结
    js 字符串加密
    jsDate()
    HDU 5430 Reflect
    HDU 5429 Geometric Progression
    HDU 5428 The Factor
    POJ 2485 Highways
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537985.html
Copyright © 2011-2022 走看看