// ********************************************************* // Implementation file StackA.cpp for the ADT stack. // Array-based implementation. // ********************************************************* #include "StackA.h" // header file stackClass::stackClass(): Top(-1) { } // end default constructor bool stackClass::StackIsEmpty() const { return bool(Top < 0); } // end StackIsEmpty void stackClass::Push(stackItemType NewItem, bool& Success) { Success = bool(Top < MAX_STACK - 1); if (Success) // if stack has room for another item { ++Top; Items[Top] = NewItem; } // end if } // end Push void stackClass::Pop(bool& Success) { Success = bool(!StackIsEmpty()); if (Success) // if stack is not empty, --Top; // pop top } // end Pop void stackClass::Pop(stackItemType& StackTop, bool& Success) { Success = bool(!StackIsEmpty()); if (Success) // if stack is not empty, { StackTop = Items[Top]; // retrieve top --Top; // pop top } // end if } // end Pop void stackClass::GetStackTop(stackItemType& StackTop, bool& Success) const { Success = bool(!StackIsEmpty()); if (Success) // if stack is not empty, StackTop = Items[Top]; // retrieve top } // end GetStackTop // End of implementation file.