您的位置:首页 > 编程语言 > C语言/C++

第十四周项目 阅读程序 3

2016-05-29 11:23 357 查看
/*
*Copyright(c) 2016, 烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:main.cpp
*作    者:李德坤
*完成日期:2016年5月29日
*版本号:v1.0
*
*问题描述:阅读程序
*输入描述:无
*输出描述:无
*/
#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));//插入到id的前面
copy(id.begin(), id.end(), outite);
cout << endl;
copy(ia+3, ia+4, back_inserter(id));//插入到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));//将ia+0到ia+2的元素插入到id中ite指定的位置
copy(id.begin(), id.end(), outite);
cout << endl;
copy(id.rbegin(), id.rend(), outite);//逆向输出id中的元素
cout << endl;
return 0;
}
/*
输出结果为:
1 2 3 4
2 1 2 3 4
2 1 2 3 4 4
2 1 2 1 2 3 4 4
4 4 3 2 1 2 1 2
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c++