/* ECP: FILEname=fig14_24.cpp */ /* 1*/ template /* 2*/ class Stack /* 3*/ { /* 4*/ Stack( const Stack & ); // Disable copy constructor. /* 5*/ Stack & operator=( const Stack & ); // Disable operator=. /* 6*/ Etype *Array; // The array of elements. /* 7*/ int TopOfStack; // Index of top element. /* 8*/ unsigned int MaxSize; // Maximum stack size; /* 9*/ public: /*10*/ enum { DefaultInitSize = 5 }; /*11*/ // Constructor. /*12*/ Stack( unsigned int InitSize = DefaultInitSize ); /*13*/ // Destructor. /*14*/ ~Stack( ) { delete [ ] Array; } /*15*/ // Member functions. /*16*/ int IsEmpty( ) const; // True if empty. /*17*/ void Push( const Etype & X ); // Push. /*18*/ const Etype & Pop( ); // Combine pop and top. /*19*/ void ClearStack( ); // Make it empty. /*20*/ }; /* 1*/ template /* 2*/ Stack::Stack( unsigned int InitSize ) /* 3*/ { /* 4*/ Array = new Etype [ MaxSize = InitSize ]; /* 5*/ if( Array == NULL ) /* 6*/ Error( "Out of memory" ); /* 7*/ ClearStack( ); /* 8*/ }