// ArrayStack.cpp // minimal array implementation of Stack; no test for overflow // wdg 2009 #include using namespace std; #include "ArrayStack.h" // constructor // arbitrarily sets upper limit ArrayStack::ArrayStack( ) : count(0) { // arr not initialized } // pushes object onto stack // @post: reference to item placed at right-end of array void ArrayStack::push( StackType item ) { arr[count++] = item; // count incremented after array access } //@ returns whether stack is empty or not bool ArrayStack::isEmpty( ) const { return (count==0); } // pops top element from stack // @returns: previous top element or ERROR if problem // @post: the top element is removed StackType ArrayStack::pop( ) { if( isEmpty() ) return ERROR; else return arr[--count]; // count decremented before array access } // @returns reference to data on top of stack // or ERROR (constant in header) if stack is empty StackType ArrayStack::peek( ) const { if( isEmpty() ) return ERROR; else return arr[count-1]; } // outputs representation void ArrayStack::dump() const { if( isEmpty() ) cout << "-empty-" << endl; else { for(int x=0; x