1. 程式人生 > >第十四周(3)-閱讀程式

第十四周(3)-閱讀程式

問題及程式碼:
/*
*煙臺大學計算機與控制工程學院
*檔名稱:yuedu3.cpp
*作    者:閆安
*完成日期:2016年6月9日
*版 本 號:codeblocks 16.01
*
*問題描述:閱讀程式3
*程式輸入:無
*程式輸出:運算結果
*/
#include <iterator>
#include <list>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
    int ia[5] = {1,2,3,4};
    list<int> id(ia, ia+4);
    ostream_iterator<int> outite(cout, " ");
    copy(id.begin(), id.end(), outite);
    cout << endl;
    copy(ia+1, ia+2, front_inserter(id));
    copy(id.begin(), id.end(), outite);
    cout << endl;
    copy(ia+3, ia+4, back_inserter(id));
    copy(id.begin(), id.end(), outite);
    cout << endl;
    list<int>::iterator ite = find(id.begin(), id.end(), 3);
    copy(ia+0, ia+2, inserter(id, ite));
    copy(id.begin(), id.end(), outite);
    cout << endl;
    copy(id.rbegin(), id.rend(), outite);
    cout << endl;
    return 0;
}
執行結果: