// Created by Frank M. Carrano and Tim Henry. // Copyright (c) 2013 __Pearson Education__. All rights reserved. /** Listing 7-1 @file ArrayStack.cpp */ #include // For assert #include "ArrayStack.h" // Header file template ArrayStack::ArrayStack() : top(-1) { } // end default constructor // Copy constructor and destructor are supplied by the compiler template bool ArrayStack::isEmpty() const { return top < 0; } // end isEmpty template bool ArrayStack::push(const ItemType& newEntry) { bool result = false; if (top < MAX_STACK - 1) // Does stack have room for newEntry? { top++; items[top] = newEntry; result = true; } // end if return result; } // end push template bool ArrayStack::pop() { bool result = false; if (!isEmpty()) { top--; result = true; } // end if return result; } // end pop template ItemType ArrayStack::peek() const { assert(!isEmpty()); // Enforce precondition // Stack is not empty; return top return items[top]; } // end peek // End of implementation file.