1 /* 2 * intlist.cpp 3 * 4 * Beispielprogramm eingebettete Klassen. 5 * Variante mit std::unique_ptr. 6 * 7 * Autor: H.Drachenfels 8 * Erstellt am: 28.11 2019 9 */
10 #include "intlist.h"
11
12 //----------------------------------------- Member-Funktionen intlist::iterator
13 intlist::iterator::iterator(element *e)
14 : current(e)
15 { }
16
17 bool intlist::iterator::operator!=(const iterator& i) const
18 {
19 return this->current != i.current;
20 }
21
22 int& intlist::iterator::operator*() const
23 {
24 return this->current->n;
25 }
26
27 intlist::iterator& intlist::iterator::operator++()
28 {
29 this->current = this->current->next.get();
30 return *this;
31 }
32
33 //--------------------------------------------------- Member-Funktionen intlist
34 intlist::intlist()
35 : head(nullptr)
36 { }
37
38 intlist& intlist::insert(int n)
39 {
40 this->head.reset(new element(this->head.release(), n));
41 return *this;
42 }
43
44 intlist::iterator intlist::begin()
45 {
46 return intlist::iterator(this->head.get());
47 }
48
49 intlist::iterator intlist::end()
50 {
51 return intlist::iterator(nullptr);
52 }
53