Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename T>
- class BiDirectionalList {
- public:
- // Node
- // It have pointers on next and previous nodes
- // Also, it is have two constructors: lvalue and rvalue
- struct Node {
- public:
- T value;
- private:
- explicit Node(const T& val, Node* prev_node, Node* next_node);
- explicit Node(T&& val, Node* prev_node, Node* next_node);
- Node* next_node_;
- Node* prev_node_;
- friend BiDirectionalList;
- };
- // Constructors and assignment operators
- BiDirectionalList() = default; // Default constructor
- BiDirectionalList(const std::initializer_list<T>& init); // InitList
- BiDirectionalList(const BiDirectionalList& second_list); // Copy constructor
- BiDirectionalList& operator=(const BiDirectionalList& second_list); // Copy
- BiDirectionalList(BiDirectionalList&& second_list); // Move constructor
- BiDirectionalList& operator=(BiDirectionalList&& second_list); // Move
- // Destructor
- ~BiDirectionalList();
- // Size methods
- int Size() const; // returns size of list
- bool IsEmpty() const; // returns true if list is empty
- // Push values
- void PushFront(const T& value); // push lvalue to front of list
- void PushFront(T&& value); // push rvalue to front of list
- void PushBack(const T& value); // push lvalue to back of list
- void PushBack(T&& value); // push rvalue to back of list
- // Get Node non constant methods/operators
- Node* Front();
- Node* Back();
- Node* operator[](int index);
- // Get Node constant methods/operators
- const Node* Front() const;
- const Node* Back() const;
- const Node* operator[](int index) const;
- // Pop
- void PopFront();
- void PopBack();
- // Convert to vector
- std::vector<T> ToVector() const;
- // Get first entry of Node
- int Find(const T& value) const;
- // Get all entries of Node
- std::vector<int> FindAll(const T& value) const;
- // Insert Node
- void InsertBefore(Node* element, const T& value); // insert lvalue before
- void InsertBefore(Node* element, T&& value); // insert rvalue before
- void InsertAfter(Node* element, const T& value); // insert lvalue after
- void InsertAfter(Node* element, T&& value); // insert rvalue after
- // Erase Node
- void Erase(Node* element);
- // Compare
- bool operator==(const BiDirectionalList<T>& second_list) const;
- bool operator!=(const BiDirectionalList<T>& second_list) const;
- private:
- void Clear();
- int size_ = 0;
- Node* front_node_ = nullptr;
- Node* back_node_ = nullptr;
- };
- template<typename T>
- class SharedPtr {
- public:
- // Constructors
- SharedPtr();
- explicit SharedPtr(T* pointer);
- SharedPtr<T>& operator=(T* pointer);
- // Copy
- SharedPtr(const SharedPtr& shared_pointer);
- SharedPtr<T>& operator=(const SharedPtr& shared_pointer);
- // Move
- SharedPtr(SharedPtr&& shared_pointer);
- SharedPtr<T>& operator=(SharedPtr&& shared_pointer);
- // Destructor
- ~SharedPtr();
- // Get pointer
- T* Get();
- const T* Get() const;
- // Release object
- void Release();
- // Operators
- T& operator*();
- T* operator->();
- const T& operator*() const;
- const T* operator->() const;
- // Equal / not equal
- bool operator==(const SharedPtr<T>& second_ptr) const;
- bool operator!=(const SharedPtr<T>& second_ptr) const;
- bool operator==(T* second_ptr) const;
- bool operator!=(T* second_ptr) const;
- template<typename S>
- friend bool operator==(S* first_ptr, const SharedPtr<S>& second_ptr);
- template<typename S>
- friend bool operator!=(S* first_ptr, const SharedPtr<S>& second_ptr);
- private:
- // Clear shared pointer
- void Destroy();
- T* pointer_;
- int* counter_;
- bool* is_correct_;
- };
Advertisement
Add Comment
Please, Sign In to add comment