// @topic T060730 Stack of integers v2 // @brief Stack class implementation with copy constructor and destructor #include "Stack.h" Stack::Stack() { std::cout << __FUNCTION__ << " invoked\n"; stack_memory = new int[ DEFAULT_CAPACITY ]; capacity = DEFAULT_CAPACITY; top_pos = 0; } Stack::Stack( int initial_capacity ) { std::cout << __FUNCTION__ << " invoked\n"; stack_memory = new int[initial_capacity]; capacity = initial_capacity; top_pos = 0; } // copy constructor Stack::Stack(Stack const& other) { std::cout << __FUNCTION__ << " invoked\n"; stack_memory = new int[other.capacity]; for (int idx = 0; idx < other.size(); ++idx) { stack_memory[idx] = other.stack_memory[idx]; } } Stack::~Stack() { std::cout << __FUNCTION__ << " invoked\n"; delete[] stack_memory; } void Stack::push( int value ) { stack_memory[ top_pos ] = value; ++top_pos; } void Stack::pop() { --top_pos; } int Stack::top() const { return stack_memory[ top_pos ]; } int& Stack::top() { return stack_memory[ top_pos ]; } int Stack::size() const { return top_pos; }