#include "Stack.h" // Destructor template Stack::~Stack() { while (!isEmpty()) { pop(); } } // Push an element onto the stack template void Stack::push(const T &data) { auto *newNode = new StackNode(data); newNode->next = top; top = newNode; count++; } // Pop the top element from the stack template T Stack::pop() { if (isEmpty()) { throw std::out_of_range("Stack is empty. Cannot pop."); } T data = top->data; StackNode *temp = top; top = top->next; delete temp; count--; return data; } // Get the top element of the stack without removing it template T Stack::peek() { if (isEmpty()) { throw std::out_of_range("Stack is empty. Cannot peek."); } return top->data; } // Get the number of elements in the stack template int Stack::getCount() const { return count; } // Check if the stack is empty template bool Stack::isEmpty() const { return count == 0; } // Explicit instantiation of the template class for the desired type(s) template class Stack;