#ifndef __Stack_CPP__ #define __Stack_CPP__ #include"Stack.h" #include templatetemplateStack::StackNode::StackNode(T2 &&data):data(std::forward(data)),last(nullptr){} templateStack::Stack():head(nullptr),total(0){} templateStack::~Stack() { clear(); } templateStack::Stack(Stack&& data) noexcept { head = data.head; total = data.total; data.head = nullptr; data.total = 0; } templateStack& Stack::operator= (Stack&& data) noexcept { head = data.head; total = data.total; data.head = nullptr; data.total = 0; return *this; } template Stack::Stack(const Stack& data) { total = data.total; head = new StackNode(data.head->data); auto from = data.head->last; auto to = head; while (from) { to->last = new StackNode(from->data); to = to->last; from = from->last; } } templateStack& Stack::operator=(const Stack& data){ total = data.total; head=new StackNode(data.head->data); auto from = data.head->last; auto to = head; while(from){ to->last = new StackNode(from->data); to = to->last; from = from->last; } return *this; } templatebool Stack::isEmpty() { return !total; } templateint Stack::size() { return total; } templatevoid Stack::clear() { while (!isEmpty()) { pop(); } delete head; } templatetemplatevoid Stack::push(T2 &&data) { if (head) { StackNode* temp = new StackNode(std::forward(data)); temp->last = head; head = temp; } else { head = new StackNode(std::forward(data)); } ++total; } templateT& Stack::front() { return head->data; } template void Stack::pop() { StackNode* temp = head; head = head->last; delete temp; --total; } #endif // !__Stack_CPP__