List Splice : list splice « List « C++






List Splice

  
#include <list>
#include <string>
#include <iostream>
using namespace std;

int main(int argc, char** argv)
{
  list<string> dictionary, bWords;

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

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

  list<string>::iterator it;
  int i;

  for (it = dictionary.begin(), i = 0; i < 3; ++it, ++i);

  dictionary.splice(it, bWords);

  for (it = dictionary.begin(); it != dictionary.end(); ++it) {
    cout << *it << endl;
  }

  return (0);
}
  
    
  








Related examples in the same category

1.Use list.splice() to remove elements in a list and insert at end of values
2.Insert all elements of list1 before the first element with value 3 of list2
3.Move first element to the end