Source of list09.cpp


  1: //list09.cpp

  3: #include <iostream>
  4: #include <list>
  5: using namespace std;

  7: int main()
  8: {
  9:     cout << "\nThis program illustrates the member functions "
 10:         "front() and back().";
 11:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 13:     int a[] = {2, 4, 6, 8, 10};
 14:     list<int> lst(a, a+5);
 15:     cout << "\nHere are the list contents:\n";
 16:     list<int>::iterator p = lst.begin();
 17:     while (p != lst.end()) cout << *p++ << " ";  cout << endl;
 18:     cout << "Press Enter to continue ... ";  cin.ignore(80, '\n');

 20:     cout << "\nThe first value in the list is "
 21:         << lst.front() << ".\n";
 22:     cout << "The last value in the list is "
 23:         << lst.back() << ".\n";
 24:     cout << "Press Enter to continue ... ";  cin.ignore(80, '\n');
 25: }