list-pop_back

////////////////////////////////////////
//      2018/04/26 8:39:49
//      list-pop_back

// removes the last element
#include <iostream>
#include <list>
#include <algorithm>
#include <numeric>
#include <iterator>

using namespace std;

int main(){
    list<int> l(5);
    iota(l.begin(),l.end(),1);
    copy(l.begin(), l.end(), ostream_iterator<int>(cout, " "));
    cout << endl;

    while (!l.empty()){
        l.pop_back();
        copy(l.begin(),l.end(),ostream_iterator<int>(cout," "));
        cout << endl;
    }
    return 0;
}

/*
OUTPUT:
    1 2 3 4 5
    1 2 3 4
    1 2 3
    1 2
    1
*/
posted @ 2018-04-26 09:10  老耗子  阅读(59)  评论(0编辑  收藏  举报