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
    */ 
  • 相关阅读:
    用Canvas绘制一个钟表
    用css3做一个3D立方体
    函数调用的不同方式,以及this的指向
    Javascript 严格模式use strict详解
    前端开发页面的性能优化方案总结
    Promise对象解读
    Vue爬坑之vuex初识
    WEB前端性能优化小结
    navicat 注册码
    docker
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537986.html
Copyright © 2011-2022 走看看