Accessing the Front and Back of a List with while loop : list begin end « list « C++ Tutorial






#include <algorithm>
#include <iostream>
#include <list>

using namespace std;

int main( )
{
   const char* name_data[] = { "A", "B","C", "D", "E","F", "G" };
   const bool girl_data[] = { true, true, false, false, true, true, true };
   const int num_graduates = sizeof( girl_data ) / sizeof( girl_data[0] );

   list< pair< string, bool > > graduate;

   while( !graduate.empty() )
   {
      cout << graduate.front().first;
      graduate.pop_front();
      if( !graduate.empty() )
      {
        cout << " and " << graduate.back().first;
        graduate.pop_back();
      }
      cout << endl;
   }
}








17.4.list begin end
17.4.1.Accessing the Front and Back of a List with while loop
17.4.2.Accessing the Front and Back of a List with for loop
17.4.3.end() is the pointer to the end of a list
17.4.4.list.begin and list.end