#include"LinkedList.h" #include #include #ifndef __LinkedList_CPP__ #define __LinkedList_CPP__ templatetemplate LinkedListNode::LinkedListNode(T2&& data) : data(std::forward(data)), next(nullptr), last(nullptr) {} template LinkedListNode::LinkedListNode(const LinkedListNode& d) : data(d.data), last(nullptr), next(nullptr) {} template LinkedListNode& LinkedListNode::operator=(const LinkedListNode& d) { data = d.data; last = nullptr; next = nullptr; return *this; } template LinkedListNode* LinkedListNode::getNext() { return next; } template LinkedListNode* LinkedListNode::getLast() { return last; } template LinkedList::LinkedList() { end = head = nullptr; total = 0; } template LinkedList::~LinkedList() { clear(); } template LinkedList::LinkedList(LinkedList&& data) noexcept :total(data.total), head(data.head),end(data.end) { data.total = 0; data.head = nullptr; data.end = nullptr; } template LinkedList& LinkedList::operator=(LinkedList&& data) noexcept { total = data.total; head = data.head; end = data.end; data.total = 0; data.head = nullptr; data.end = nullptr; return *this; } template LinkedList::LinkedList(const LinkedList& data) { end = head = nullptr; total = 0; for (auto head = data.head; head; head = head->next) { add(head->data); } } template LinkedList& LinkedList::operator=(const LinkedList& data) { end = head = nullptr; total = 0; for (auto head = data.head; head; head = head->next) { add(head->data); } return *this; } template bool LinkedList::isEmpyt() { return !total; } template int LinkedList::size() { return total; } template void LinkedList::clear() { while (head) { remove(head); } } template template void LinkedList::add(T2&& data) { if (!head) { end = head = new LinkedListNode(std::forward(data)); if (!head)return; head->next = head->last = nullptr; } else { LinkedListNode* temp = new LinkedListNode(std::forward(data)); if (!temp)return; temp->last = end; temp->next = nullptr; end->next = temp; end = temp; } ++total; } template LinkedListNode* LinkedList::getHead() { return head; } template LinkedListNode* LinkedList::getEnd() { return end; } template void LinkedList::remove(LinkedListNode* node) { if (node == head) { head = head->next; } if (node == end) { end = end->last; } if (node->last) { node->last->next = node->next; } if (node->next) { node->next->last = node->last; } --total; delete node; } template void LinkedList::sort(bool(*cmp)(const T& a, const T& b)) { for (auto i = head; i; i = i->next) { auto temp = i; for (auto j = i; j; j = j->next) { if (!cmp(temp->data, j->data))temp = j; } std::swap(i->data,temp->data); } } #endif // !__LinkedList_CPP__