zoukankan      html  css  js  c++  java
  • list-push_front

    ////////////////////////////////////////
    //      2018/04/26 14:08:56
    //      list-push_front
    
    // add an element to the front of the list
    #include <iostream>
    #include <list>
    #include <iomanip>
    #include <string>
    
    using namespace std;
    
    template<class T>
    class Name
    {
    private:
        T first, last;
    public:
        Name(T f, T l) :first(f), last(l){};
        void print(){
            cout.setf(ios::left);
            cout << setw(15) << first << " " << last << endl;
        }
    };
    //=======================
    
    int main(){
        typedef Name<string> N;
        typedef list<N> L;
        L l;
        L::iterator it;
    
        N n1(string("Albert"), string("Johnson"));
        N n2("Lana", "Vinokur");
    
        l.push_front(n1);
        l.push_front(n2);
    
        // unamed object
        l.push_front(N("Linda","Bain"));
    
        it = l.begin();
        while (it != l.end()){
            (it++)->print();
        }
        cout << endl;
        return 0;
    }
    
    /*
        OUTPUT:
        Linda           Bain
        Lana            Vinokur
        Albert          Johnson
    */
  • 相关阅读:
    16款值得一用的iPhone线框图模板 (PSD & Sketch)
    设计神器
    {CF812}
    hiho1080(多标记线段树)
    {容斥原理}
    {dp入门}
    {AC自动机}
    CF807
    Trie树
    杂记
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537948.html
Copyright © 2011-2022 走看看