Mega Code Archive

 
Categories / C++ Tutorial / List
 

Accessing the Front and Back of a List with while loop

#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;    } }