Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. //
  2. // Created by wolski on 07.04.2020.
  3. //
  4.  
  5. #ifndef MYLIST4STUDENTS_MYLIST_H
  6. #define MYLIST4STUDENTS_MYLIST_H
  7.  
  8.  
  9. #include <memory>
  10. #include <iostream>
  11.  
  12.  
  13.  
  14. template<class T>
  15. class MyListItr;
  16.  
  17. template<typename T>
  18. class MyList {
  19. private:
  20.     int _size;
  21.     friend class MyListItr<T>;
  22. public:
  23.     class Node {
  24.     private:
  25.         T value;
  26.     public:
  27.         std::unique_ptr<MyList::Node> next{ nullptr };
  28.  
  29.         Node() = delete;
  30.         Node(T& value, MyList::Node* next) :value(value), next(next) {};
  31.         T getVal()const { return value; };
  32.         void setVal(T value) { this->value = value; };
  33.         ~Node() {};
  34.     };
  35.  
  36.     std::unique_ptr<MyList::Node> head;
  37.     MyList(const MyList<T>&) = delete;
  38.     MyList& operator=(const MyList<T>) = delete;
  39.     MyList() :_size(0), head(nullptr) {};
  40.     int size()const { return _size; };
  41.     void push_front(T);
  42.     T pop_front();
  43.     T front()const;
  44.     void remove(T);
  45.     MyListItr<T> begin();
  46.     MyListItr<T> end();
  47.     friend std::ostream& operator<<(std::ostream& os, const MyList&);
  48.     typedef MyListItr<T> iterator;
  49.     typedef T value_type;
  50.     typedef T* pointer;
  51.     typedef std::ptrdiff_t difference_type;
  52.     typedef T& reference;
  53.     typedef size_t size_type;
  54.  
  55. };
  56.  
  57. template<typename T>
  58. class MyListItr : public std::iterator<std::output_iterator_tag, T> {
  59.     typename MyList<T>::Node* data;
  60.  
  61. public:
  62.     MyListItr(typename MyList<T>::Node*data):data(data) {}
  63.  
  64.     bool operator!=(MyListItr<T>const& Tx)const;
  65.     MyListItr<T> operator++();
  66.     T operator*();
  67.  
  68. };
  69.  
  70.  
  71. #endif //MYLIST4STUDENTS_MYLIST_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement