#include <iostream>
#include <list>
using namespace std;
typedef list<int> intList;
typedef list<int>::iterator intListItor;
template<class T, class A>
void showList(const list<T, A>& aList);
int main()
{
// define a list of integers with 5 elements
intList ListA(5);
int j = 0;
for (intListItor ia = ListA.begin(); ia != ListA.end(); ++ia)
*ia = 5 * j++;
cout << "ListA" << "\n";
showList(ListA);
// define a list of integers with 6 elements
intList ListB(6);
j = 0;
for (intListItor ib = ListB.begin(); ib != ListB.end(); ++ib)
*ib = 100 * j++;
cout << "ListB" << "\n";
showList(ListB);
// splice!
cout << "Splice:\n";
ListA.splice(++ListA.begin(), ListB, ++(++ListB.begin()), --ListB.end());
cout << "ListA" << "\n";
showList(ListA);
cout << "ListB" << "\n";
showList(ListB);
return 0;
}
//
// Display list elements
//
template<class T, class A>
void showList(const list<T, A>& aList)
{
cout << "size() = " << aList.size() << ":\t";
for (list<T, A>::const_iterator i = aList.begin(); i != aList.end(); ++i)
cout << *i << ", ";
cout << "\n\n";
}