#ifndef INC_08_TEAM_PROJECT_STACK_H #define INC_08_TEAM_PROJECT_STACK_H #include #include "StackNode.h" template class Stack { private: StackNode *top; int count; public: Stack() : top(nullptr), count(0) {}; // Destructor ~Stack(); // Check if the stack is empty [[nodiscard]] bool isEmpty() const { return count == 0; }; // Get the number of elements in the stack [[nodiscard]] int getCount() const { return count; }; // Push an element onto the stack void push(const T &data); // Pop the top element from the stack T pop(); // Get the top element of the stack without removing it T peek(); }; template Stack::~Stack() { while (!isEmpty()) { pop(); } } template void Stack::push(const T &data) { auto *newNode = new StackNode(data); newNode->next = top; top = newNode; count++; } 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; } template T Stack::peek() { if (isEmpty()) { throw std::out_of_range("Stack is empty. Cannot peek."); } return top->data; } #endif //INC_08_TEAM_PROJECT_STACK_H