C++ examples for STL:deque
Loop through deque in the reverse direction using a reverse_iterator.
#include <iostream> #include <deque> using namespace std; void show(const char *msg, deque<int> q); int main() {/*from w w w . j a va 2 s . c o m*/ //Declare a deque that has an initial capacity of 10. deque<int> dq(10); for(unsigned i=0; i < dq.size(); ++i) dq[i] = i*i; // Declare an iterator to a deque<int>. deque<int>::iterator itr; // Now, declare reverse iterator to a deque<int> deque<int>::reverse_iterator ritr; // Cycle through dq in the reverse direction using a reverse_iterator. for(ritr = dq.rbegin(); ritr != dq.rend(); ++ritr) cout << *ritr << " "; cout << "\n\n"; return 0; } // Display the contents of a deque<int>. void show(const char *msg, deque<int> q) { cout << msg; for(unsigned i=0; i < q.size(); ++i) cout << q[i] << " "; cout << "\n"; }