C++ examples for STL:deque
Loop through deque in the forward direction using an iterator.
#include <iostream> #include <deque> using namespace std; void show(const char *msg, deque<int> q); int main() {/*from w w w . java 2 s. com*/ //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 forward direction using an iterator. cout << "Cycle through the deque in the forward direction:\n"; for(itr = dq.begin(); itr != dq.end(); ++itr) cout << *itr << " "; cout << "\n\n"; cout << "Now, use a reverse iterator to cycle through in the" << " reverse direction:\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"; }