diff --git a/lista.cpp b/lista.cpp index 7d2a42d..47418bb 100644 --- a/lista.cpp +++ b/lista.cpp @@ -63,4 +63,11 @@ Lista& Lista::operator=(Lista &&rhs) { return *this; } +template +Lista& operator+(Lista &l1, const Lista &l2) { + for(auto it(l2.Begin()); it != l2.End(); it++) + l1.Push_Back(*it); + return l1; +} + #endif // LISTA_CPP diff --git a/lista.h b/lista.h index e424d1e..20b1e5b 100644 --- a/lista.h +++ b/lista.h @@ -44,6 +44,20 @@ class Lista { }; + class Reverse_Iterator { + Cvor* pok; + public: + Reverse_Iterator(Cvor *cvor = nullptr):pok(cvor) {} + Tip operator*() { return pok->element; } + Reverse_Iterator operator--() { pok = pok->sljedeci; return *this; } + Reverse_Iterator operator--(int) { Reverse_Iterator za_vracanje(*this); pok = pok->sljedeci; return za_vracanje; } + Reverse_Iterator operator++() { pok = pok->prethodni; return *this; } + Reverse_Iterator operator++(int) { Reverse_Iterator za_vracanje(*this); pok = pok->prethodni; return za_vracanje; } + bool friend operator==(Reverse_Iterator it1, Reverse_Iterator it2) { return it1.pok == it2.pok; } + bool friend operator!=(Reverse_Iterator it1, Reverse_Iterator it2) { return !(it1==it2); } + friend class Lista; + }; + Lista() { init(); } Lista(int n, Tip vrijednost) { init(); while(n-- > 0) Push_Back(vrijednost); } Lista(const Lista &kopija); @@ -56,6 +70,8 @@ class Lista { Const_Iterator End() const { return rep; } Iterator Begin() { return glava->sljedeci; } Iterator End() { return rep; } + Reverse_Iterator RBegin() {return rep->prethodni;} + Reverse_Iterator REnd() {return glava;} Iterator Insert(Iterator pozicija, const Tip vrijednost); void Push_Back(const Tip vrijednost) { Insert(End(),vrijednost); } @@ -67,6 +83,11 @@ class Lista { bool Empty() const { return broj_elemenata == 0; } void Clear() { while(!Empty()) PopFront(); } + Lista& operator+=(const Lista &l) {*this = *this + l; return *this;} + Lista& operator+=(Lista &&rhs) {rep->prethodni->slijedeci = rhs.glava->slijedeci; rep = rhs.rep; broj_elemenata += rhs.broj_elemenata; + rhs.glava = nullptr; rhs.rep = nullptr; rhs.broj_elemenata = 0; return *this;} + template + friend Lista& operator+(Lista &l1, const Lista &l2); }; #include "lista.cpp"