#include <string>
#include <list>
#include <iostream>

using namespace std;

int main()
{
  list<string> my_list_of_strings;

  // Put some items on the end of the list
  my_list_of_strings.push_back("first");
  my_list_of_strings.push_back("second");
  my_list_of_strings.push_back("third");

  // Check the first item
  if (my_list_of_strings.front() == "first")
    cout << "First item is \"first\", as we thought." << endl;

  // Now let's iterate over the items in the list
  {
    cout << "The list is:" << endl;

    // We'll use a constant iterator because we don't intend on
    // modifying the items it points to.

    list<string>::const_iterator an_item;
    for (an_item = my_list_of_strings.begin();
         an_item != my_list_of_strings.end();
         an_item++)
    {
      cout << *an_item << endl;
    }
  }

  // Now let's iterate over the items in the list, but reversed
  {
    cout << "The reversed list is:" << endl;

    list<string>::const_iterator an_item = my_list_of_strings.end();
    do
    {
      an_item--;
      cout << *an_item << endl;
    }
    while (an_item != my_list_of_strings.begin());
  }

  return 0;
}

