有关Iterators and Reverse Iterators的程序
#include <iostream>
#include <deque>
#include <algorithm>
using namespace std;
void print (int elem)
{
cout << elem << ' ';
}
int main()
{
deque<int> coll;
for (int i=1; i<=9; ++i) {
coll.push_back(i);
}
deque<int>::iterator pos1;
pos1 = find (coll.begin(), coll.end(), 2);
deque<int>::iterator pos2;
pos2 = find (coll.begin(), coll.end(),7);
for_each (pos1, pos2, print);
cout << endl;
deque<int>::reverse_iterator rpos1(pos1);
deque<int>::reverse_iterator rpos2(pos2);
for.each (rpos2, rpos1, print);
cout << endl;
}
the output of the program is as follows:
2 3 4 5 6
6 5 4 3 2
为什么输出是6 5 4 3 2,如何将Iterators范围转化为Reverse Iterators