Accessing the Front and Back of a List with for 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;

   for( int i = 0; i < num_graduates; ++i )
      if( girl_data[i] )
         graduate.push_front(
            make_pair( name_data[i], girl_data[i] ) );
      else
         graduate.push_back(
            make_pair( name_data[i], girl_data[i] ) );
}








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