Assigning deque objects. : Deque « Data Structure « C++





Assigning deque objects.

Assigning deque objects.

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

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

  for(i = 0; i <10; i++) 
     dequeObject1[i] = i + 'A';
  cout << "Contents of dequeObject1 are: ";
  for(i = 0; i <dequeObject1.size(); i++)
    cout << dequeObject1[i];
  cout << "\n\n";

  // assign one deque to another
  dequeObject2 = dequeObject1;

  cout << "Size of dequeObject2 is " << dequeObject2.size() << endl;
  cout << "Contents of dequeObject2 are: ";
  for(i = 0; i <dequeObject2.size(); i++)
    cout << dequeObject2[i];
  cout << "\n\n";

  dequeObject2.assign(dequeObject1.begin()+2, dequeObject1.end()-2);

  cout << "Size of dequeObject2 is " << dequeObject2.size() << endl;
  cout << "Contents of dequeObject2 are: ";
  for(i = 0; i <dequeObject2.size(); i++)
    cout << dequeObject2[i];
  cout << "\n\n";

  dequeObject2.assign(8, 'X');

  cout << "Size of dequeObject2 is " << dequeObject2.size() << endl;
  cout << "Contents of dequeObject2 are: ";
  for(i = 0; i <dequeObject2.size(); i++)
    cout << dequeObject2[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.Reverse iterators and copy.Reverse iterators and copy.
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