Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lista.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,11 @@ Lista<Tip>& Lista<Tip>::operator=(Lista<Tip> &&rhs) {
return *this;
}

template <typename tip>
Lista<tip>& operator+(Lista<tip> &l1, const Lista<tip> &l2) {
for(auto it(l2.Begin()); it != l2.End(); it++)
l1.Push_Back(*it);
return l1;
}

#endif // LISTA_CPP
21 changes: 21 additions & 0 deletions lista.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tip>;
};

Lista() { init(); }
Lista(int n, Tip vrijednost) { init(); while(n-- > 0) Push_Back(vrijednost); }
Lista(const Lista<Tip> &kopija);
Expand All @@ -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); }
Expand All @@ -67,6 +83,11 @@ class Lista {

bool Empty() const { return broj_elemenata == 0; }
void Clear() { while(!Empty()) PopFront(); }
Lista<Tip>& operator+=(const Lista<Tip> &l) {*this = *this + l; return *this;}
Lista<Tip>& operator+=(Lista<Tip> &&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 <typename tip>
friend Lista<tip>& operator+(Lista<tip> &l1, const Lista<tip> &l2);
};

#include "lista.cpp"
Expand Down