I do not know how to write the emplace method for the sheet. Here is my sheet:
#pragma once #include <iostream> #include <iterator> #include <algorithm> #include <initializer_list> #include <memory> #include <utility> using std::ostream; using std::istream; template <class T> class LinkedList { protected: struct Node { T _value; Node *_pNext; Node *_pPrev; Node(T val) : _value(val), _pNext(NULL), _pPrev(NULL) {}; Node() : _value(0), _pNext(NULL), _pPrev(NULL) {}; T GetValue() { return _value; } }; private: Node *_pHead; Node *_pTail; int _size; public: LinkedList() : _pHead(NULL), _pTail(NULL), _size(0) {} LinkedList(const LinkedList<T>& other) : _pHead(NULL), _pTail(NULL), _size(0) { if (this == &other) { return; } for (auto it = other.begin(); it != other.end(); it++) { AddFirst(*it); } } LinkedList(std::initializer_list<T> _list) { for (auto it = _list.begin(); it != _list.end(); it++) { AddLast((*it)); } } LinkedList(LinkedList<T>&& other) : _pHead(NULL), _pTail(NULL), _size(0) { _pHead = other._pHead; _pTail = other._pTail; _size = other._size; other._pHead = NULL; other._pTail = NULL; other._size = 0; std::cout << "create move LinkedList" << std::endl; } bool operator==(const LinkedList &other) const { Node* current = _pHead; Node* other_cur = other._pHead; if (_size != other.GetSize()) { return false; } if (_size == 0 && other._size == 0) { return true; } while (current->_pNext != 0) { if (current->_value != other_cur->_value) { return false; } current = current->_pNext; other_cur = other_cur->_pNext; } if (current->_value != other_cur->_value) { return false; } return true; } class iterator : public std::iterator<std::input_iterator_tag, T> { Node* _node; public: iterator(Node* temp) : _node(temp) {} iterator(const iterator& iter) : _node(iter._node) {} iterator& operator++() { _node = _node->_pNext; return *this; } iterator operator++(int) { iterator temp(*this); operator++(); return temp; } bool operator==(const iterator& it) { return _node == it._node; } bool operator!=(const iterator& it) { return _node != it._node; } T& operator*() { return _node->_value; } }; iterator begin() const { return iterator(_pHead); } iterator end() const { return iterator(_pTail->_pNext); } void AddFirst(const T val) { Node* node = new Node(val); Node* temp = _pHead; _pHead = node; _pHead->_pNext = temp; if (_size == 0) { _pTail = _pHead; } else { temp->_pPrev = _pHead; } _size++; } void AddLast(const T val) { Node* node = new Node(val); if (_size == 0) { _pHead = node; } else { _pTail->_pNext = node; node->_pPrev = _pTail; } _pTail = node; _size++; } void Add(const T val) { AddLast(val); } template <typename ...Args > void Emplace(Args && ...args) { } }; I would be grateful for the help)
Node, which takesArgs&&... args, and everything else is the same as in theAddLastmethod - diraria