Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Created by wolski on 07.04.2020.
- //
- #ifndef MYLIST4STUDENTS_MYLIST_H
- #define MYLIST4STUDENTS_MYLIST_H
- #include <memory>
- #include <iostream>
- template<class T>
- class MyListItr;
- template<typename T>
- class MyList {
- private:
- int _size;
- friend class MyListItr<T>;
- public:
- class Node {
- private:
- T value;
- public:
- std::unique_ptr<MyList::Node> next{ nullptr };
- Node() = delete;
- Node(T& value, MyList::Node* next) :value(value), next(next) {};
- T getVal()const { return value; };
- void setVal(T value) { this->value = value; };
- ~Node() {};
- };
- std::unique_ptr<MyList::Node> head;
- MyList(const MyList<T>&) = delete;
- MyList& operator=(const MyList<T>) = delete;
- MyList() :_size(0), head(nullptr) {};
- int size()const { return _size; };
- void push_front(T);
- T pop_front();
- T front()const;
- void remove(T);
- MyListItr<T> begin();
- MyListItr<T> end();
- friend std::ostream& operator<<(std::ostream& os, const MyList&);
- typedef MyListItr<T> iterator;
- typedef T value_type;
- typedef T* pointer;
- typedef std::ptrdiff_t difference_type;
- typedef T& reference;
- typedef size_t size_type;
- };
- template<typename T>
- class MyListItr : public std::iterator<std::output_iterator_tag, T> {
- typename MyList<T>::Node* data;
- public:
- MyListItr(typename MyList<T>::Node*data):data(data) {}
- bool operator!=(MyListItr<T>const& Tx)const;
- MyListItr<T> operator++();
- T operator*();
- };
- #endif //MYLIST4STUDENTS_MYLIST_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement