Use insert iterator adaptors to insert one deque into another by way of the copy() algorithm. : deque iterator « deque « C++ Tutorial






#include <iostream>
#include <iterator>
#include <deque>
#include <string>

using namespace std;

void show(const char *msg, deque<string> dq);

int main()
{
  deque<string> dq, dq2, dq3, dq4;

  dq.push_back("A");
  dq.push_back("B");
  dq.push_back("C");
  dq.push_back("D");
  dq.push_back("E");
  dq.push_back("F.");

  dq2.push_back("G");
  dq2.push_back("H");
  dq2.push_back("I");

  dq3.push_back("J");
  dq3.push_back("K");
  dq3.push_back("L");

  dq4.push_back("M");
  dq4.push_back("N");
  dq4.push_back("O");

  cout << dq.size() << endl;
  show("Original contents of dq:", dq);

  // Use an insert_iterator to insert dq2 into dq.
  copy(dq2.begin(), dq2.end(), inserter(dq, dq.begin()+3));

  cout << "Size of dq after inserting dq2: " << dq.size() << endl;
  show("dq2:", dq);

  // Use a back_insert_iterator to insert dq3 into dq.
  copy(dq3.begin(), dq3.end(), back_inserter(dq));

  cout << "Size of dq after inserting dq3: ";
  cout << dq.size() << endl;
  show("dq3:", dq);

  // Use a front_insert_iterator to insert dq4 into dq.
  copy(dq4.begin(), dq4.end(), front_inserter(dq));

  cout << "Size of dq after inserting dq4: " << dq.size() << endl;
  show("dq4:", dq);

  return 0;
}

void show(const char *msg, deque<string> dq) {
  cout << msg << endl;
  for(unsigned i=0; i < dq.size(); ++i)
    cout << dq[i] << endl;
}








22.6.deque iterator
22.6.1.Define iterator for deque
22.6.2.deque::iterator and deque::reverse_iterator
22.6.3.Using the Front of a Deque
22.6.4.Use iterator and reverse_iterator with deque
22.6.5.Print the contents in reverse order using reverse_iterator and functions rbegin() and rend()
22.6.6.Create an empty deque and then assign it a sequence that is the reverse of deque
22.6.7.Use insert iterator adaptors to insert one deque into another by way of the copy() algorithm.