diff --git a/20230406/aux/hallo.txt b/20230406/aux/hallo.txt new file mode 100644 index 0000000000000000000000000000000000000000..8095a184a9b9ae8a14a0f0cde697c7f7cf1410e6 --- /dev/null +++ b/20230406/aux/hallo.txt @@ -0,0 +1 @@ +Hallo, Welt! diff --git a/20230406/iterators-01.cpp b/20230406/iterators-01.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3429606a4490f5ab06ba77371a6850b155706c0a --- /dev/null +++ b/20230406/iterators-01.cpp @@ -0,0 +1,9 @@ +#include <iostream> + +int main () +{ + int prime[5] = { 2, 3, 5, 7, 11 }; + for (int *p = prime; p != prime + 5; p++) + std::cout << *p << std::endl; + return 0; +} diff --git a/20230406/iterators-02.cpp b/20230406/iterators-02.cpp new file mode 100644 index 0000000000000000000000000000000000000000..13b3f45e3e612ddd4519d9168acc8b35ff86e1c7 --- /dev/null +++ b/20230406/iterators-02.cpp @@ -0,0 +1,9 @@ +#include <iostream> + +int main () +{ + int prime[5] = { 2, 3, 5, 7, 11 }; + for (int *p = prime; p <= prime + 4; p++) + std::cout << *p << std::endl; + return 0; +} diff --git a/20230406/iterators-03.cpp b/20230406/iterators-03.cpp new file mode 100644 index 0000000000000000000000000000000000000000..714302447a77591f24f6812da7f375d37f6e0a25 --- /dev/null +++ b/20230406/iterators-03.cpp @@ -0,0 +1,10 @@ +#include <iostream> +#include <array> + +int main () +{ + std::array <int, 5> prime = { { 2, 3, 5, 7, 11 } }; + for (std::array <int, 5>::iterator p = prime.begin (); p != prime.end (); p++) + std::cout << *p << std::endl; + return 0; +} diff --git a/20230406/iterators-04.cpp b/20230406/iterators-04.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3b04a800d57d6ba533671e319c751b1e5348d3ae --- /dev/null +++ b/20230406/iterators-04.cpp @@ -0,0 +1,10 @@ +#include <iostream> +#include <vector> + +int main () +{ + std::vector <int> prime = { { 2, 3, 5, 7, 11 } }; + for (std::vector <int>::iterator p = prime.begin (); p != prime.end (); p++) + std::cout << *p << std::endl; + return 0; +} diff --git a/20230406/iterators-05.cpp b/20230406/iterators-05.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7c62ad835e980d3f2393757ad743d2faad262515 --- /dev/null +++ b/20230406/iterators-05.cpp @@ -0,0 +1,14 @@ +#include <iostream> +#include <vector> + +int main () +{ + std::vector <int> prime = { { 2, 3, 5, 7, 11 } }; + for (std::vector <int>::iterator p = prime.begin (); p != prime.end (); p++) + std::cout << *p << std::endl; + prime.push_back (13); + prime.push_back (17); + for (std::vector <int>::iterator p = prime.begin (); p != prime.end (); p++) + std::cout << *p << std::endl; + return 0; +} diff --git a/20230406/iterators-06.cpp b/20230406/iterators-06.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8698385665db3b31275ec01525d6b84dd8ed3a57 --- /dev/null +++ b/20230406/iterators-06.cpp @@ -0,0 +1,14 @@ +#include <iostream> +#include <vector> + +int main () +{ + std::vector <int> prime = { { 2, 3, 5, 7, 11 } }; + for (auto p = prime.begin (); p != prime.end (); p++) + std::cout << *p << std::endl; + prime.push_back (13); + prime.push_back (17); + for (auto p = prime.begin (); p != prime.end (); p++) + std::cout << *p << std::endl; + return 0; +} diff --git a/20230406/iterators-07.cpp b/20230406/iterators-07.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e7ca0b01d8fab62e914dfc8013d3b7241c09f02f --- /dev/null +++ b/20230406/iterators-07.cpp @@ -0,0 +1,14 @@ +#include <iostream> +#include <vector> + +int main () +{ + std::vector <int> prime = { { 2, 3, 5, 7, 11 } }; + for (auto p : prime) + std::cout << *p << std::endl; + prime.push_back (13); + prime.push_back (17); + for (auto p : prime) + std::cout << *p << std::endl; + return 0; +} diff --git a/20230406/iterators-08.cpp b/20230406/iterators-08.cpp new file mode 100644 index 0000000000000000000000000000000000000000..80328d1ede64acaf9ad67a5c402ee6c361b37fa1 --- /dev/null +++ b/20230406/iterators-08.cpp @@ -0,0 +1,14 @@ +#include <iostream> +#include <vector> + +int main () +{ + std::vector <int> prime = { { 2, 3, 5, 7, 11 } }; + for (auto &p : prime) + std::cout << p << std::endl; + prime.push_back (13); + prime.push_back (17); + for (auto &p : prime) + std::cout << p << std::endl; + return 0; +} diff --git a/20230406/iterators-09.cpp b/20230406/iterators-09.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a1c2005a263464e99776974404086a75e3f46a8a --- /dev/null +++ b/20230406/iterators-09.cpp @@ -0,0 +1,14 @@ +#include <iostream> +#include <list> + +int main () +{ + std::list <int> prime = { { 2, 3, 5, 7, 11 } }; + for (auto &p : prime) + std::cout << p << std::endl; + prime.push_back (13); + prime.push_back (17); + for (auto &p : prime) + std::cout << p << std::endl; + return 0; +} diff --git a/20230406/templates-01.cpp b/20230406/templates-01.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b6d013e09364e0d8cf5569215fe4f4d935c69d74 --- /dev/null +++ b/20230406/templates-01.cpp @@ -0,0 +1,23 @@ +#include <iostream> +#include <string> + +using std::cout; +using std::endl; +using std::string; + +void print (int x) +{ + cout << x << endl; +} + +void print (string x) +{ + cout << x << endl; +} + +int main () +{ + print (42); + print ("Hello, world!"); + return 0; +} diff --git a/20230406/templates-02.cpp b/20230406/templates-02.cpp new file mode 100644 index 0000000000000000000000000000000000000000..191e3000629fc94071fcecc3be94077e9c7db360 --- /dev/null +++ b/20230406/templates-02.cpp @@ -0,0 +1,19 @@ +#include <iostream> +#include <string> + +using std::cout; +using std::endl; +using std::string; + +template <typename t> +void print (t x) +{ + cout << x << endl; +} + +int main () +{ + print (42); + print ("Hello, world!"); + return 0; +} diff --git a/20230406/templates-03.cpp b/20230406/templates-03.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6166f19ccac0771319f0c933de6f4d40b7160bbb --- /dev/null +++ b/20230406/templates-03.cpp @@ -0,0 +1,17 @@ +#include <iostream> + +using std::cout; +using std::endl; + +template <typename t> +void print (t x) +{ + cout << x << endl; +} + +int main () +{ + print (42); + print ("Hello, world!"); + return 0; +} diff --git a/20230406/templates-04.cpp b/20230406/templates-04.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4fca6712426ce894917c93bacfaadccd1fdab88f --- /dev/null +++ b/20230406/templates-04.cpp @@ -0,0 +1,24 @@ +#include <iostream> + +using std::cout; +using std::endl; + +class bla +{ + int content; +}; + +template <typename t> +void print (t x) +{ + cout << x << endl; +} + +int main () +{ + print (42); + print ("Hello, world!"); + bla blubb; + print (blubb); + return 0; +} diff --git a/20230406/templates-07.cpp b/20230406/templates-07.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4279b334c08faebaacd2759bbb48e89389525d1a --- /dev/null +++ b/20230406/templates-07.cpp @@ -0,0 +1,35 @@ +#include <iostream> + +using std::cout; +using std::endl; + +class bla +{ +public: + int content; + bla (int x): + content (x) + { + } +}; + +template <typename t> +void print (t x) +{ + cout << x << endl; +} + +template <> +void print (bla x) +{ + cout << x.content << endl; +} + +int main () +{ + print (42); + print ("Hello, world!"); + bla blubb (137); + print (blubb); + return 0; +} diff --git a/20230406/templates-08.cpp b/20230406/templates-08.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a0c3a29492a197cad3a8b9df9d25f6dea735fa41 --- /dev/null +++ b/20230406/templates-08.cpp @@ -0,0 +1,41 @@ +#include <iostream> + +using std::cout; +using std::endl; + +class bla +{ +public: + int content; + bla (int x): + content (x) + { + } +}; + +template <typename t> +void print (t x) +{ + cout << x << endl; +} + +template <> +void print (int x) +{ + cout << "Die Antwort lautet: " << x << endl; +} + +template <> +void print (bla x) +{ + cout << x.content << endl; +} + +int main () +{ + print (42); + print ("Hello, world!"); + bla blubb (137); + print (blubb); + return 0; +} diff --git a/20230406/templates-09.cpp b/20230406/templates-09.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2606961e8a1c3a85645a333e4867cc82edd50608 --- /dev/null +++ b/20230406/templates-09.cpp @@ -0,0 +1,41 @@ +#include <iostream> + +using std::cout; +using std::endl; + +class bla +{ +public: + int content; + bla (int x): + content (x) + { + } +}; + +template <typename t> +void print (t x) +{ + cout << x << endl; +} + +template <> +void print (int x) +{ + cout << "Die Antwort lautet: " << x << endl; +} + +template <> +void print (bla x) +{ + cout << x << endl; // Fehler wird erkannt, obwohl nicht instantiiert. +} // Dies ist nicht immer der Fall. + +int main () +{ + print (42); + print ("Hello, world!"); + bla blubb (137); +// print (blubb); + return 0; +} diff --git a/20230406/templates-10.cpp b/20230406/templates-10.cpp new file mode 100644 index 0000000000000000000000000000000000000000..88fc5a10f5491f7a033885d619d904c93cb98cea --- /dev/null +++ b/20230406/templates-10.cpp @@ -0,0 +1,54 @@ +#include <iostream> +#include <string> + +using namespace std; + +template <typename argtype> +class list +{ + struct node + { + argtype content; + node *next; + }; + node *root; +public: + list (); + void insert (argtype x); + void output (); +}; + +template <typename argtype> +list <argtype>::list () +{ + root = NULL; +} + +template <typename argtype> +void list <argtype>::insert (argtype x) +{ + node *n = new node; + n->content = x; + n->next = root; + root = n; +} + +template <typename argtype> +void list <argtype>::output () +{ + for (list *p = root; p; p = p->next) + cout << p->content << endl; +} + +int main () +{ + list <string> s; + s.insert ("one"); + s.insert ("two"); + s.insert ("three"); + list <int> i; + i.insert (1); + i.insert (2); + i.insert (3); + return 0; +} diff --git a/20230406/templates-11.cpp b/20230406/templates-11.cpp new file mode 100644 index 0000000000000000000000000000000000000000..57aec679a2d56a4f3c9e8e84e3460309ec7d2720 --- /dev/null +++ b/20230406/templates-11.cpp @@ -0,0 +1,56 @@ +#include <iostream> +#include <string> + +using namespace std; + +template <typename argtype> +class list +{ + struct node + { + argtype content; + node *next; + }; + node *root; +public: + list (); + void insert (argtype x); + void output (); +}; + +template <typename argtype> +list <argtype>::list () +{ + root = NULL; +} + +template <typename argtype> +void list <argtype>::insert (argtype x) +{ + node *n = new node; + n->content = x; + n->next = root; + root = n; +} + +template <typename argtype> +void list <argtype>::output () +{ + for (list *p = root; p; p = p->next) + cout << p->content << endl; +} + +int main () +{ + list <string> s; + s.insert ("one"); + s.insert ("two"); + s.insert ("three"); + s.output (); + list <int> i; + i.insert (1); + i.insert (2); + i.insert (3); + i.output (); + return 0; +} diff --git a/20230406/templates-12.cpp b/20230406/templates-12.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e5d654753a19253f9d2d478071d3ba985d8ef1ea --- /dev/null +++ b/20230406/templates-12.cpp @@ -0,0 +1,56 @@ +#include <iostream> +#include <string> + +using namespace std; + +template <typename argtype> +class list +{ + struct node + { + argtype content; + node *next; + }; + node *root; +public: + list (); + void insert (argtype x); + void output (); +}; + +template <typename argtype> +list <argtype>::list () +{ + root = NULL; +} + +template <typename argtype> +void list <argtype>::insert (argtype x) +{ + node *n = new node; + n->content = x; + n->next = root; + root = n; +} + +template <typename argtype> +void list <argtype>::output () +{ + for (node *p = root; p; p = p->next) + cout << p->content << endl; +} + +int main () +{ + list <string> s; + s.insert ("one"); + s.insert ("two"); + s.insert ("three"); + s.output (); + list <int> i; + i.insert (1); + i.insert (2); + i.insert (3); + i.output (); + return 0; +} diff --git a/20230406/templates-13.cpp b/20230406/templates-13.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3577e9f853a2d50197193b20ad40d734f314f283 --- /dev/null +++ b/20230406/templates-13.cpp @@ -0,0 +1,61 @@ +#include <iostream> +#include <string> + +using namespace std; + +template <typename argtype> +class list +{ + struct node + { + argtype content; + node *next; + }; + node *root; +public: + list (); + void insert (argtype x); + void output (); +}; + +template <typename argtype> +list <argtype>::list () +{ + root = NULL; +} + +template <typename argtype> +void list <argtype>::insert (argtype x) +{ + node *n = new node; + n->content = x; + n->next = root; + root = n; +} + +template <typename argtype> +void list <argtype>::output () +{ + for (node *p = root; p; p = p->next) + cout << p->content << endl; +} + +void blabla (int x) +{ + huddeldibuddel (wuppdich); +} + +int main () +{ + list <string> s; + s.insert ("one"); + s.insert ("two"); + s.insert ("three"); + s.output (); + list <int> i; + i.insert (1); + i.insert (2); + i.insert (3); + i.output (); + return 0; +} diff --git a/20230406/templates-14.cpp b/20230406/templates-14.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b42e532f0a066ae1cd9991686967670c08c7e796 --- /dev/null +++ b/20230406/templates-14.cpp @@ -0,0 +1,54 @@ +#include <iostream> +#include <string> + +using namespace std; + +template <typename argtype> +class list +{ + struct node + { + argtype content; + node *next; + }; + node *root; +public: + list (); + void insert (argtype x); + void output (); +}; + +template <typename argtype> +list <argtype>::list () +{ + root = NULL; +} + +template <typename argtype> +void list <argtype>::insert (argtype x) +{ + node *n = new node; + n->content = x; + n->next = root; + root = n; +} + +template <typename argtype> +void list <argtype>::output () +{ + for (huddeldibuddel *p = root; p; p = p->next) + cout << p->content << endl; +} + +int main () +{ + list <string> s; + s.insert ("one"); + s.insert ("two"); + s.insert ("three"); + list <int> i; + i.insert (1); + i.insert (2); + i.insert (3); + return 0; +} diff --git a/20230406/templates-15.cpp b/20230406/templates-15.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e8296e01cb5a66017ad9c4382e575bdd84989b43 --- /dev/null +++ b/20230406/templates-15.cpp @@ -0,0 +1,54 @@ +#include <iostream> +#include <string> + +using namespace std; + +template <typename argtype> +class list +{ + struct node + { + argtype content; + node *next; + }; + node *root; +public: + list (); + void insert (argtype x); + void output (); +}; + +template <typename argtype> +list <argtype>::list () +{ + root = NULL; +} + +template <typename argtype> +void list <argtype>::insert (argtype x) +{ + node *n = new node; + n->content = x; + n->next = root; + root = n; +} + +template <typename argtype> +void list <argtype>::output () +{ + for (char *p = root; p; p = p->next) + cout << p->content << endl; +} + +int main () +{ + list <string> s; + s.insert ("one"); + s.insert ("two"); + s.insert ("three"); + list <int> i; + i.insert (1); + i.insert (2); + i.insert (3); + return 0; +} diff --git a/20230406/templates-16.cpp b/20230406/templates-16.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d023eeeb690ef2ba6032903f8564422a4a20a469 --- /dev/null +++ b/20230406/templates-16.cpp @@ -0,0 +1,64 @@ +#include <iostream> +#include <string> + +using namespace std; + +template <typename argtype> +class list +{ + struct node + { + argtype content; + node *next; + }; + node *root; +public: + list (); + void insert (argtype x); + void output (); +}; + +template <typename argtype> +list <argtype>::list () +{ + root = NULL; +} + +template <typename argtype> +void list <argtype>::insert (argtype x) +{ + node *n = new node; + n->content = x; + n->next = root; + root = n; +} + +template <typename argtype> +void list <argtype>::output () +{ + for (node *p = root; p; p = p->next) + cout << p->content << endl; +} + +template <> +void list <int>::output () +{ + for (node *p = root; p; p = p->next) + cout << p->content << " "; + cout << endl; +} + +int main () +{ + list <string> s; + s.insert ("one"); + s.insert ("two"); + s.insert ("three"); + s.output (); + list <int> i; + i.insert (1); + i.insert (2); + i.insert (3); + i.output (); + return 0; +}