// complexContainer.cpp // tom bailey 1 oct 08 // Demonstrate a complex container: list of vector, vector // of list, list of list, etc. #include using std::vector; #include using std::list; #include using std::string; #include using std::cout; using std::endl; using std::cin; #include using std::max; // pre: The sequence referenced by it..itend contains the // string "begin" followed by the string "end". // post: The number of strings between the first "begin" and // the first following "end" has been returned. template< typename Iter > int between( Iter it, Iter itend ) { while( *it != string( "begin" ) ) { ++it; } int count( 0 ); while( *it != string( "end" ) ) { ++count; ++it; } return count; } // pre: it..itend references a sequence of sequences of // strings. Each sequence of strings has a between // value. // post: The largest between value for any of the sequences // of strings in the containers referenced by it..itend // has been returned. template< typename Iter > int mostBetween( Iter it, Iter itend ) { int most( -1 ); while( it != itend ) { most = max( most, between( (*it).begin(), (*it).end() ) ); ++it; } return most; } template< typename Container > void csFill( Container & cont, int btwn ) { int pre = rand() % 200; for( int i=0; i void ccsFill( Container & cont, Element empty ) { int btwn( 0 ); cin >> btwn; while( btwn >= 0 ) { cont.push_back( Element() ); csFill( cont.back(), btwn ); cin >> btwn; } } int main() { vector< list< string > > foo1; ccsFill( foo1, list() ); cout << mostBetween( foo1.begin(), foo1.end() ) << endl; list< vector< string > > foo2; ccsFill( foo2, vector() ); cout << mostBetween( foo2.begin(), foo2.end() ) << endl; return 0; }