Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- template<typename T>
- class list {
- private:
- class ListNodeBase {
- public:
- ListNodeBase* next;
- ListNodeBase* prev;
- ListNodeBase()
- : next(nullptr)
- , prev(nullptr)
- {}
- };
- class ListNode: public ListNodeBase {
- public:
- T value;
- explicit ListNode(const T& value)
- :value(value)
- {}
- };
- size_t count;
- ListNodeBase head;
- public:
- class ListIterator {
- private:
- ListNodeBase* current;
- public:
- explicit ListIterator(ListNodeBase* current)
- : current(current)
- {}
- const T& operator * () const {
- return static_cast<ListNode*>(current)->value;
- }
- T& operator * () {
- return static_cast<ListNode*>(current)->value;
- }
- ListIterator& operator++ () {
- current = current->next;
- return *this;
- }
- ListIterator& operator-- () {
- current = current->prev;
- return *this;
- }
- bool operator == (const ListIterator& other) const {
- return current == other.current;
- }
- bool operator != (const ListIterator& other) const {
- return current != other.current;
- }
- };
- void insert() {
- }
- void erase(ListNodeBase* position) {
- if (position != &head) {
- auto item = static_cast<ListNode*>(position);
- item->prev->next = item->next;
- item-> ...
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement