#ifndef STACK_DYNAMIC #define STACK_DYNAMIC template class Stack { T* vals; unsigned topInd; unsigned size; void resize(); public: Stack(); ~Stack(); Stack(Stack& other) = delete; Stack& operator=(const Stack& other) = delete; void push(const T& v); void pop(); T& top(); }; template void Stack::resize() { unsigned newSize = size << 1; T* newVals = new T[newSize]; for (unsigned i = 0; i < size; i++) newVals[i] = vals[i]; delete vals; vals = newVals; size = newSize; } template Stack::Stack() { vals = new T[1]; // for testing purposes its 1 } template Stack::~Stack() { delete[] vals; } template void Stack::push(const T& v) { if (topInd == size) resize(); vals[topInd++] = v; } template void Stack::pop() { topInd--; } template T& Stack::top() { return vals[topInd - 1]; } #endif