Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. template<typename T>
  4. class list {
  5. private:
  6.     class ListNodeBase {
  7.     public:
  8.         ListNodeBase* next;
  9.         ListNodeBase* prev;
  10.         ListNodeBase()
  11.             : next(nullptr)
  12.             , prev(nullptr)
  13.         {}
  14.     };
  15.     class ListNode: public ListNodeBase {
  16.     public:
  17.         T value;
  18.         explicit ListNode(const T& value)
  19.             :value(value)
  20.         {}
  21.     };
  22.     size_t count;
  23.     ListNodeBase head;
  24. public:
  25.     class ListIterator {
  26.     private:
  27.         ListNodeBase* current;
  28.     public:
  29.         explicit ListIterator(ListNodeBase* current)
  30.             : current(current)
  31.         {}
  32.         const  T& operator * () const {
  33.             return static_cast<ListNode*>(current)->value;
  34.         }
  35.         T& operator * () {
  36.             return static_cast<ListNode*>(current)->value;
  37.         }
  38.         ListIterator& operator++ () {
  39.             current = current->next;
  40.             return *this;
  41.         }
  42.         ListIterator& operator-- () {
  43.             current = current->prev;
  44.             return *this;
  45.         }
  46.         bool operator == (const ListIterator& other) const {
  47.             return current == other.current;
  48.         }
  49.         bool operator != (const ListIterator& other) const {
  50.             return current != other.current;
  51.         }
  52.     };
  53.     void insert() {
  54.        
  55.     }
  56.     void erase(ListNodeBase* position) {
  57.         if (position != &head) {
  58.             auto item = static_cast<ListNode*>(position);
  59.             item->prev->next = item->next;
  60.             item-> ...
  61.         }
  62.     }
  63. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement