// L-11 MCS 360 Fri 17 Sep 2010 : use_stl_list.cpp

/* The program below illustrates the use of the STL list */

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

void write ( list<string> L );
// writes the list of strings

int main()
{
   list<string> L;

   L.push_back("hello");
   L.push_back("how");
   L.push_back("are");
   L.push_back("you");

   cout << "number of elements : "
        << L.size() << endl;

   cout << "the strings :";
   write(L);

   cout << "give a word : ";
   string word;
   cin >> word;

   list<string>::iterator i;
   i = find(L.begin(),L.end(),word);
   if(i != L.end())
      cout << "found \"" << *i 
           << "\"" << endl;
   else
      cout << "did not find \""
           << word << "\"" << endl;

   list<string>::iterator j;
   j = find(L.begin(),L.end(),"how");
   L.erase(j);
   cout << "after erasing \"how\" :";
   write(L);
 
   j = find(L.begin(),L.end(),"are");
   L.insert(j,"who");
   cout << "after inserting \"who\" :";
   write(L);

   return 0;
}

void write ( list<string> L )
{
   for(list<string>::const_iterator i = L.begin();
       i != L.end(); i++)
      cout << " " << *i;  
   cout << endl;
}


