/** @file StackA.cpp * Implementation of the stack ADT using arrays. */ #include "C6-StackA.h" // Stack class specification file // Default constructor Stack::Stack() : top(-1) { } bool Stack::isEmpty() const { return top < 0; } void Stack::push(const StackItemType& newItem) throw(StackException) { // if stack has no more room for another item if (top >= MAX_STACK-1) throw StackException("StackException: stack full on push"); else{ ++top; items[top] = newItem; } } void Stack::pop() throw(StackException) { if (isEmpty()) throw StackException("StackException: stack empty on pop"); else --top; // stack is not empty; pop top } void Stack::pop(StackItemType& stackTop) throw(StackException) { if (isEmpty()) throw StackException("StackException: stack empty on pop"); else{ // stack is not empty; retrieve top stackTop = items[top]; --top; // pop top } } void Stack::getTop(StackItemType& stackTop) const throw(StackException) { if (isEmpty()) throw StackException("StackException: stack empty on getTop"); else // stack is not empty; retrieve top stackTop = items[top]; }