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
    */ 
  • 相关阅读:
    python3-file的修改实现类似shell中sed的功能
    python3-字典的循环
    python3-file文件操作
    python3-字典的增删改查
    python3-字典中存储列表
    python3-字典中的一些常用方法
    python3-字典中包含字典
    报错调试和工具使用
    (三)、Struts第三天
    struts体系结构
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537986.html
Copyright © 2011-2022 走看看