Reverse iterators and copy. : Deque « Data Structure « C++






Reverse iterators and copy.

Reverse iterators and copy.

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

int main()
{
  deque<char> dequeObject1(30), dequeObject2, dequeObject3;
  int i;

  char str1[] = "forward";
  for(i = 0; str1[i]; i++) 
     dequeObject2.push_back(str1[i]);

  copy(dequeObject2.begin(), dequeObject2.end(), dequeObject1.begin());

  cout << "Contents dequeObject1 after forward copy:\n";
  for(i = 0; i <dequeObject1.size(); i++)
    cout << dequeObject1[i];
  cout << "\n\n";

  char str2[] = "backward";
  for(i = 0; str2[i]; i++) 
     dequeObject3.push_back(str2[i]);

  copy(dequeObject3.rbegin(), dequeObject3.rend(), dequeObject1.begin()+strlen(str1));

  cout << "Contents dequeObject1 after reverse copy:\n";
  for(i = 0; i <dequeObject1.size(); i++)
    cout << dequeObject1[i];

  return 0;
}


           
       








Related examples in the same category

1.One way to reverse-copy a deque.One way to reverse-copy a deque.
2.Use reverse iterators.Use reverse iterators.
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