// List class with Iterator // for illustration purposes only, no robust implementation ( no error-ckecking, etc) #include using std::cout; using std::endl; #include #include #include "list.h" // List class definition void print( int& intValue) { cout << intValue << " "; } int main() { // test List of int values List< int > integerList; cout << "insertAtFront square numbers:\n"; for( int i = 0; i < 10; ++i) integerList.insertAtFront( i*i ); List< int >::Iterator listIter( integerList ); // using iterator like pointer: for( int j = 0; j < 10; ++j) { cout << *listIter << " "; ++listIter; } cout << endl; // using iterator with STL algorithms: cout << "Summe: " << std::accumulate( integerList.begin(), integerList.end(), 0 ); cout << "\nAusgabe der Werte:\n"; std::for_each( integerList.begin(), integerList.end(), print ); cout << endl << endl; return 0; } // end main