#ifndef _lvpstack_H #define _lvpstack_H /* Lawrenceville Press lvpstack type DECLARATION */ /* This library file modified to operate with CodeWarrior 3.3 */ /* June 1997, updated March 1999 comments updated */ /* */ /* The lvpstack class is based on the class apstack defined */ /* for use in the AP Computer Science courses. */ /* */ /* Inclusion of the C++ classes defined for use in the */ /* Advanced Placement Computer Science courses does not */ /* constitute endorsement of the other material in */ /* "A Guide to Programming in C++" (Lawrenceville Press, */ /* June 1997) by the College Board, Educational Testing */ /* Service, or the AP Computer Science Development Committee. */ // comment line below if bool is a built-in type //#include // ******************************************************************* // Last Revised: 8/14/98 // // APCS stack class // ******************************************************************* #include // used for stack implementation template class lvpstack { public: // constructors/destructor lvpstack( ); // construct empty stack lvpstack( const lvpstack & s ); // copy constructor ~lvpstack( ); // destructor // assignment const lvpstack & operator = ( const lvpstack & rhs ); // accessors const itemType & top( ) const; // return top element (NO pop) bool isEmpty( ) const; // return true if empty, else false int length( ) const; // return number of elements in stack // modifiers void push( const itemType & item ); // push item onto top of stack void pop( ); // pop top element void pop( itemType & item ); // combines pop and top void makeEmpty( ); // make stack empty (no elements) private: int myTop; // index of top element lvpvector myElements; // storage for stack }; // ********************************************************************** // // Specifications for stack functions // // Any violation of a function's precondition will result in an error message // followed by a call to exit. // // // constructors/destructor // // stack( ) // postcondition: the stack is empty // // stack( const stack & s ) // postcondition: stack is a copy of s // // ~stack( ) // postcondition: stack is destroyed // // assignment // // const stack & operator = ( const stack & rhs ) // postcondition: normal assignment via copying has been performed // // accessors // // const itemType & top( ) const // precondition: stack is [e1, e2, ... en] with n >= 1 // postcondition: returns en // // bool isEmpty( ) const // postcondition: returns true if stack is empty, false otherwise // // int length( ) const // postcondition: returns # of elements currently in stack // // modifiers // // void push( const itemType & item ) // precondition: stack is [e1, e2...en] with n >= 0 // postcondition: stack is [e1, e2, ... en, item] // // void pop( ) // precondition: stack is [e1, e2, ... en] with n >= 1 // postcondition: stack is [e1, e2, ... e(n-1)] // // // void pop(itemType & item ) // precondition: stack is [e1,e2,...en] with n >= 1 // postcondition: stack is [e1,e2,...e(n-1)] and item == en // // void makeEmpty( ) // postcondition: stack is empty // // Examples of variable definition // // stack istack; // creates empty stack of integers // stack dstack; // creates empty stack of doubles // #include #endif