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