/* * list.h * * Created on: 31.10.2013 * Author: trifon */ #ifndef LIST_H_ #define LIST_H_ #include using namespace std; template class List { public: // проверява дали списъкът е празен virtual bool empty() const = 0; // включване на елемент преди позиция virtual bool insertBefore(T const&, I const&) = 0; // включване на елемент след позиция virtual bool insertAfter(T const&, I const&) = 0; // изключване на елемент преди позиция virtual bool deleteBefore(T&, I const&) = 0; // изключване на елемент след позиция virtual bool deleteAfter(T&, I const&) = 0; // изключване на елемент на позиция virtual bool deleteAt(T&, I&) = 0; // итератор към началото virtual I begin() const = 0; // итератор към края virtual I end() const = 0; void toEnd(T const& x) { insertAfter(x, end()); } }; template class Iterator { public: // it++; // Iterator operator++(int) = 0; // ++it; // преместване, връща новата стойност virtual Iterator& operator++() = 0; // if (it) { ... } else { ... } // проверка за валидност virtual operator bool() const = 0; // cout << l.getElementAt(it); // cout << *it; // *it = 3; // получаване и установяване на стойност през итератор virtual T& operator*() const = 0; // сравняване на итератори virtual bool operator==(Iterator const&) const = 0; bool operator!=(Iterator const& it) const { return !(*this == it); } }; template ostream& operator<<(ostream& os, List const& l) { for(I it = l.begin(); it; it++) os << *it << ' '; return os << endl; } #endif /* LIST_H_ */