#include"CycleLinkedList.h" #include #ifndef __CycleLinkedList_CPP__ #define __CycleLinkedList_CPP__ templatetemplate CycleLinkedListNode::CycleLinkedListNode(T2 &&data) : data(std::forward(data)), next(nullptr), last(nullptr) {} template CycleLinkedListNode* CycleLinkedListNode::getNext() { return next; } template CycleLinkedListNode* CycleLinkedListNode::getLast() { return last; } template CycleLinkedListNode::CycleLinkedListNode(const CycleLinkedListNode& d):data(d.data),last(nullptr),next(nullptr){} template CycleLinkedListNode& CycleLinkedListNode::operator=(const CycleLinkedListNode& d) { data = d.data; last = nullptr; next = nullptr; return *this; } template CycleLinkedList::CycleLinkedList() { head = nullptr; total = 0; } template CycleLinkedList::~CycleLinkedList() { clear(); } template CycleLinkedList::CycleLinkedList(CycleLinkedList&& data) noexcept:total(data.total),head(data.head) { data.total = 0; data.head = nullptr; } template CycleLinkedList& CycleLinkedList::operator=(CycleLinkedList&& data) noexcept { total = data.total; head = data.head; data.total = 0; data.head = nullptr; return *this; } template CycleLinkedList::CycleLinkedList(const CycleLinkedList& data) { head=nullptr; total=0; if (data.total != 0) { add(data.head->data); for (auto head = data.head->next; head != data.head; head = head->next) { add(head->data); } } } template CycleLinkedList& CycleLinkedList::operator=(const CycleLinkedList& data) { head=nullptr; total=0; if (data.total != 0) { add(data.head->data); for (auto head = data.head->next; head != data.head; head = head->next) { add(head->data); } } return *this; } template bool CycleLinkedList::isEmpyt() { return !total; } template int CycleLinkedList::size() { return total; } template void CycleLinkedList::clear() { while (head) { remove(head); } } template template void CycleLinkedList::add(T2&& data) { if (!head) { head = new CycleLinkedListNode(std::forward(data)); if (!head)return; head->next = head->last = head; } else { CycleLinkedListNode* temp = new CycleLinkedListNode(std::forward(data)); if (!temp)return; temp->last = head->last; temp->next = head; head->last->next = temp; head->last = temp; } ++total; } template CycleLinkedListNode* CycleLinkedList::getHead() { return head; } template void CycleLinkedList::remove(CycleLinkedListNode* node) { if (node->next == node) { this->head = nullptr; } else { if (node == head) head = head->next; node->next->last = node->last; node->last->next = node->next; } --total; delete node; } #endif // !__CycleLinkedList_CPP__