// Project Stack // File stack.cpp #include "stack.h" Stack::Stack(int n) { array = new int[n]; size = n; top = array - 1; } Stack::~Stack() { delete[] array; } void Stack::push(int value) { if (!is_full()) *(++top) = value; } void Stack::pop() { if (!is_empty()) top--; } int Stack::peek() { if (!is_empty()) return *top; else return 0; } bool Stack::is_full() { return top >= array + size - 1; } bool Stack::is_empty() { return top < array; }