diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Bachelor/Prog2/ListIterator/ListIter.cpp | |
| download | Studium-master.tar.gz Studium-master.tar.bz2 | |
Diffstat (limited to 'Bachelor/Prog2/ListIterator/ListIter.cpp')
| -rw-r--r-- | Bachelor/Prog2/ListIterator/ListIter.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
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 <iostream>
+using std::cout;
+using std::endl;
+
+#include <numeric>
+#include <algorithm>
+
+#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 |
