C++ examples for STL:deque
Get the last and first element from deque
#include <iostream> #include <deque> using namespace std; void show(const char *msg, deque<int> q); int main() {/*from ww w.ja v a 2s. 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; cout << "The first and last element in dq as" << " pointed to by begin() and end()-1:\n" << *dq.begin() << ", " << *(dq.end()-1) << "\n\n"; cout << "The first and last element in dq as" << " pointed to by rbegin() and rend()-1:\n" << *dq.rbegin() << ", " << *(dq.rend()-1) << "\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"; }