Iterator values may change. : Deque « Data Structure « C++






Iterator values may change.

Iterator values may change.


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

int main()
{
  deque<char> dequeObject;
  deque<char>::iterator p1, p2;
  int i;

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

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

  p1 = dequeObject.begin() + 2;
  p2 = dequeObject.begin() + 3;
  cout << "*p1: " << *p1 << ", ";
  cout << "*p2: " << *p2 << endl;
  cout << endl;

  dequeObject.insert(p1, 'X');

  cout << "Sequence after insert: ";
  for(i = 0; i <dequeObject.size(); i++)
    cout << dequeObject[i] << " ";
  cout << endl;

  cout << "*p1: " << *p1 << ", ";
  cout << "*p2: " << *p2 << endl;

  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.Assigning deque objects.Assigning deque objects.
5.Demonstrate swap() for dequeDemonstrate swap() for deque
6.Demonstrate resize() for dequeDemonstrate resize() for deque
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