#include #include #include "stack.h" Stack::Stack() : first(nullptr) { } bool Stack::empty() const { return first == nullptr; } void Stack::push(int const& i) { first = new Element(i, first); } void Stack::pop() { if ( empty() ) { throw Empty_Stack("empty stack"); } Element* victim{ first }; first = victim->next; victim->next = nullptr; delete victim; } int Stack::top() const { if ( empty() ) { throw Empty_Stack("empty stack"); } return first->data; } Stack::Element::Element(int const& i, Element* n) : data{i}, next{n} { }