One way to reverse-copy a deque. : Deque « Data Structure « C++






One way to reverse-copy a deque.

One way to reverse-copy a deque.

#include <iostream>
#include <deque>
using namespace std;

int main()
{
  deque<char> dequeObject;
  deque<char> reversedQueue;
  int i;

  for(i = 0; i <10; i++) 
     dequeObject.push_back('A'+i);

  cout << "Contents of dequeObject: ";
  for(i = 0; i <dequeObject.size(); i++) 
    cout << dequeObject[i];
  cout << endl;

  while(!dequeObject.empty()) {
    reversedQueue.push_front(dequeObject.front());
    dequeObject.pop_front();
  }
  
  cout << "Contents of reversedQueue: ";
  for(i = 0; i <reversedQueue.size(); i++) 
    cout << reversedQueue[i];
    
  return 0;
}


           
       








Related examples in the same category

1.Use reverse iterators.Use reverse iterators.
2.Reverse iterators and copy.Reverse iterators and copy.
3.Assigning deque objects.Assigning deque objects.
4.Demonstrate swap() for dequeDemonstrate swap() for deque
5.Demonstrate resize() for dequeDemonstrate resize() for deque
6.Iterator values may change.Iterator values may change.
7.Demonstrate raw storage iteratorsDemonstrate raw storage iterators
8.Demonstrate a deque.Demonstrate a deque.
9.Deque: push, pop, sort, find, begin, end, insertDeque: push, pop, sort, find, begin, end, insert