/////////////////////////////////////////////////////////// // // array_stack.h // // For the CS127 assignment, due 1/13/03. // Jeff Ondich // // This is the interface for a class called ArrayStack. // Your job is to write the corresponding array_stack.cpp // that implements the member functions described below. // // Note that this is a stack of limited size (limited // by the constant kMaxSize) that holds only strings. // Later, we will discuss how to allow the stack to grow // without bound and to hold data other than strings. // /////////////////////////////////////////////////////////// #include using namespace std; class ArrayStack { public: enum { kMaxSize = 100 }; // The zero-parameter constructor initializes the // stack to empty. ArrayStack(); // The destructor for this class has nothing to do, but // it's good policy to give every class an explicit // destructor in anticipation of future modifications // to the class. virtual ~ArrayStack(); // These return true if the array is empty or full, respectively. bool IsEmpty(); bool IsFull(); // Returns the item on the top of the stack, or the empty string // if the stack is empty. string Top(); // Adds the given string to the top of the stack if the stack is not full. // If the stack is full, this operation has no effect. void Push( const string& s ); // Removes the top item from the stack if the stack is not empty. // If the stack is empty, this operation has no effect. void Pop(); private: string stack[kMaxSize]; int stackPointer; };