C++ deque const_iterator const_reverse_iterator运用实例

shangs00 2019-12-29

C++ deque const_iterator const_reverse_iterator运用实例

#include <iterator>
#include <iostream>
#include <deque>
#include <algorithm>

using namespace std;

void print1(int elem1)
{
    cout << "" << elem1 << endl;
}

int main()
{
    deque<int> deque1 = {1,2,3,4,5,6,7,8,9};
    deque<int>::const_iterator c_iter1;
    c_iter1 = find(deque1.cbegin(),deque1.cend(),2);

    deque<int>::const_iterator c_iter2;
    c_iter2 = find(deque1.cbegin(), deque1.cend(), 7);

    for_each(c_iter1, c_iter2, print1);
    cout << endl;

    deque<int>::const_reverse_iterator r_iter1(c_iter1);
    deque<int>::const_reverse_iterator r_iter2(c_iter2);
    for_each(r_iter2,r_iter1,print1);
    cout << endl;

    system("pause");
    return 0;
}

2
3
4
5
6

6
5
4
3
2

请按任意键继续. . .

代码参考:C++标准库(第2版)

相关推荐