// This is a modified version of example 20.17 of Deitel & Deitel

// Fig. 20.17: fig20_17.cpp
// Testing Standard Library class list
#include <iostream>
#include <list>
#include <algorithm>
using std::cout;
using std::endl;
using std::list;

template <class T>
void printList(const list<T> &listRef)
{
    typename list<T>::const_iterator iter;
    
    for (iter = listRef.begin(); iter != listRef.end(); iter++)
    {
        cout << *iter << ' ';
    }
    cout << endl;
}

int main()
{ 
    const int SIZE = 4;
    int a[ SIZE ] = { 2, 6, 4, 8 };
    list<int> values, otherValues;
    
    values.push_front( 1 );
    values.push_front( 2 );
    values.push_back( 4 );
    values.push_back( 3 );
    
    cout << "values contains: ";
    printList( values );
    values.sort();
    cout << "\nvalues after sorting contains: ";
    printList( values );
    
    otherValues.insert( otherValues.begin(), a, a + SIZE );
    cout << "\notherValues contains: ";
    printList( otherValues );
    values.splice( values.end(), otherValues );
    cout << "\nAfter splice values contains: ";
    printList( values );
    cout << "\nAfter splice otherValues contains: ";
    printList( otherValues );
    
    values.sort();
    cout << "\nvalues contains: ";
    printList( values );
    otherValues.insert( otherValues.begin(), a, a + SIZE );
    otherValues.sort();
    cout << "\notherValues contains: ";
    printList( otherValues );
    values.merge( otherValues );
    cout << "\nAfter merge:\n   values contains: ";
    printList( values );
    cout << "\n   otherValues contains: ";
    printList( otherValues );
    
    values.pop_front();
    values.pop_back();   // all sequence containers
    cout << "\nAfter pop_front and pop_back values contains:\n";
    printList( values );
    
    values.unique();
    cout << "\nAfter unique values contains: ";
    printList( values );
    
    // method swap is available in all containers
    values.swap( otherValues );
    cout << "\nAfter swap:\n   values contains: ";
    printList( values );
    cout << "\n   otherValues contains: ";
    printList( otherValues );
    
    values.assign( otherValues.begin(), otherValues.end() );
    cout << "\nAfter assign values contains: ";
    printList( values );
    
    values.merge( otherValues ); 
    cout << "\nvalues contains: ";
    printList( values ); 
    values.remove( 4 );
    cout << "\nAfter remove( 4 ) values contains: ";
    printList( values );
    cout << endl;
    return 0;
}




