#ifndef LIST_H #define LIST_H #include namespace ecci { class List { private: struct Node { double data; Node* previous; Node* next; public: explicit Node(const double& data, Node* previous = nullptr, Node* next = nullptr) : data(data) , previous(previous) , next(next) { } }; public: class ConstIterator { }; struct Iterator { private: Node* node; public: explicit Iterator(Node* node) : node(node) { } inline bool operator!=(const Iterator& other) const { return node != other.node; } inline double& operator*() { return node->data; } // Pre-increment: ++itr inline const Iterator& operator++() { node = node->next; return *this; } // Post-increment: itr++ inline Iterator operator++(int) { Iterator before(*this); node = node->next; return before; } // Pre-decrement: --itr inline const Iterator& operator--() { node = node->previous; return *this; } }; inline Iterator begin() { return Iterator(head); } inline Iterator rbegin() { return Iterator(tail); } inline Iterator end() { return Iterator(nullptr); } inline Iterator rend() { return Iterator(nullptr); } private: Node* head; Node* tail; size_t count; public: List() : head(nullptr), tail(nullptr), count(0) { } inline bool isEmpty() const { return head == nullptr; } inline size_t getCount() const { return count; } bool add(const double& value) { if ( isEmpty() ) { head = tail = new Node(value); if ( tail ) ++count; return tail != nullptr; } tail->next = new Node(value, tail); if ( tail->next == nullptr ) return false; tail = tail->next; return ++count > 0; } void print() const { for ( Node* current = head; current; current = current->next ) std::cout << current->data << ", " ; } }; } // namespace ecci #endif // LIST_H