From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- Bachelor/Prog2/ListIterator/ListIter.cpp | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Bachelor/Prog2/ListIterator/ListIter.cpp (limited to 'Bachelor/Prog2/ListIterator/ListIter.cpp') diff --git a/Bachelor/Prog2/ListIterator/ListIter.cpp b/Bachelor/Prog2/ListIterator/ListIter.cpp new file mode 100644 index 0000000..166850c --- /dev/null +++ b/Bachelor/Prog2/ListIterator/ListIter.cpp @@ -0,0 +1,46 @@ +// 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 \ No newline at end of file -- cgit v1.2.3