#ifndef STACK_DYNAMICSEQ #define STACK_DYNAMICSEQ template class Stack { struct Node { T value; Node* next; Node(const T& v, Node* n) : value(v), next(n) {} }; Node* topNode; public: Stack(); ~Stack(); Stack(Stack& other) = delete; Stack& operator=(const Stack& other) = delete; void push(const T& v); void pop(); T& top(); }; template Stack::Stack() : topNode() {} template Stack::~Stack() { while (topNode != nullptr) pop(); } template void Stack::push(const T& v) { topNode = new Node(v, topNode); } template void Stack::pop() { Node* old = topNode; topNode = topNode->next; delete old; } template T& Stack::top() { return topNode->value; } #endif