1: //deque07.cpp
3: #include <iostream>
4: #include <deque>
5: using namespace std;
7: int main()
8: {
9: cout << "\nThis program illustrates reverse iterators of the "
10: "deque class,\nas well as member functions rbegin() and "
11: "rend().";
12: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
14: cout << "\nHere are the contents of a deque of size 12:\n";
15: int a[] = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24};
16: deque<int> d(a, a+12);
17: deque<int>::iterator p = d.begin();
18: while (p != d.end()) cout << *p++ << " ";
19: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
21: cout << "\nNow using a reverse iterator to display\n"
22: "the deque components in reverse order:\n";
23: deque<int>::reverse_iterator r_p = d.rbegin();
24: while (r_p != d.rend()) cout << *r_p++ << " ";
25: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
27: cout << "\nNow using a reverse iterator to display\n"
28: "the deque components in forward order:\n";
29: r_p = d.rend();
30: while (r_p != d.rbegin()) cout << *--r_p << " ";
31: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
33: cout << "\nNow constructing a new deque containing the "
34: "values from 18 down to 6 from\nthe first deque, and "
35: "then displaying the values from this new deque.\n";
36: deque<int> d1(d.rbegin()+3, d.rbegin()+10);
37: p = d1.begin();
38: while (p != d1.end()) cout << *p++ << " ";
39: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
40: }