summaryrefslogtreecommitdiffstats
path: root/Bachelor/Prog2/ListIterator/ListIter.cpp
blob: 166850c440c49c11b122b781ce689d7eec645a9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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