// A Quick and dirty array implemntation of a stack template // defines the parameters of the class class stack { public: // Note it is much easier to put these inline in a template class. stack(){ next_free=0; } int push(X n){ if( is_full() )return 0; else { s[next_free++]=n; return 1; } }//push int pop(){ if( is_empty() )return 0; else{ s[--next_free]; return 1; } }//pop int get_top(X& item){ if( is_empty() ) return 0; else{ item = s[next_free-1]; return 1; } }//get_top int is_empty() const{ return next_free<=0; } int is_full() const{ return next_free>=max_size; } private: X s[ max_size ]; // the items in the stack are in s[0..next_free-1] int next_free; //points at the next available place // and is also number in the stack };//class stack // How about implementing the linked stack in the book // with the same interface(public functions)