我是靠谱客的博主 虚幻狗,这篇文章主要介绍第十四周阅读程序(3),现在分享给大家,希望可以做个参考。

问题及代码:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#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; }

运行结果:

知识点:

id.rbegin(), id.rend()

容器定义的反向迭代器rbegin,rend

分别返回指向容器尾元素和首元素前一位置的反向迭代器



最后

以上就是虚幻狗最近收集整理的关于第十四周阅读程序(3)的全部内容,更多相关第十四周阅读程序(3)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(78)

评论列表共有 0 条评论

立即
投稿
返回
顶部