//----------------------------------------------------------------- // // templates3.cpp // // A template-based stack. This is a template version of the array // based stack we first encountered back in Unit III. // // written by: Elizabeth Sklar // modified : 19th May 2010 // //----------------------------------------------------------------- #include #include using namespace std; // The class definition. // // Note that all the functions are defined inside the class definition. template class stack { public: explicit stack( int size=100 ) : max_len(size), top(EMPTY), s(new TYPE[size]) {assert( s != 0 );} ~stack() { delete []s; } void reset() { top = EMPTY; } void push( TYPE c ) { s[++top] = c; } TYPE pop() { return s[top--]; } TYPE top_of() const { return s[top]; } bool empty() const { return( top == EMPTY ); } bool full() const { return( top == max_len - 1 ); } private: enum { EMPTY = -1 }; TYPE *s; int max_len; int top; }; // A function that uses the stack to reverse an array of characters. void reverse( char *str[], int n ) { stack stk(n); int i; for ( i=0; i ./a.out abc def 123 int main( int argc, char *argv[] ) { int i; cout << "before:\n"; for ( i=0; i