首页 > 代码库 > reverse iterator
reverse iterator
Problem 1:
vector<int> coll = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };vector<int>::const_iterator pos = find (coll.cbegin(), coll.cend(),5);cout << "pos: " << *pos << endl;vector<int>::const_reverse_iterator rpos(pos);cout << "rpos: " << *rpos << endl;
This program has the following output:
pos: 5
rpos: 4
Same position but its value is changed; this can use the pos in the diagram to illustrate it.
Problem 2:
deque<int> coll = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };deque<int>::const_iterator pos1;pos1 = find (coll.cbegin(), coll.cend(), 2); // valuedeque<int>::const_iterator pos2;pos2 = find (coll.cbegin(), coll.cend(), 7); // valuefor_each (pos1, pos2, print); // operationdeque<int>::const_reverse_iterator rpos1(pos1);deque<int>::const_reverse_iterator rpos2(pos2);for_each (rpos2, rpos1, print); // operation
The program is as follows:
2 3 4 5 6
6 5 4 3 2
It seems the behavior of the problem 2 is not same with problem 1.
This can use the pos1, pos2 in the diagram to illustrate it.
reverse iterator
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。