1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

For the virtual base class vstack(Vstack.h)

template<class T>
class Gstack {
public:
virtual void push(
T) = 0;// pure virtual function
virtual Tpop() = 0; // pure virtual function
virtual bool isempty() = 0;// pure virtual fun.
virtual bool isfull() = 0; // pure virtual fun.
};

For a derivation of stacks using arrays(See Arraystack.h)

#include <assert.h>
template
<class T>
class Array_stack :public Gstack<T>{
int sz;
int top;
T*the_stack;
public:
Array_stack(int Nitems)
{ sz = Nitems; the_stack = new
T[sz]; top = sz; }
Array_stack()
{ sz = 100; the_stack = new T[sz]; top = sz; }
~Array_stack()
{ delete[] the_stack; }
void push(Tx)
{ assert( !isfull() );
the_stack[--top] = x; }
Tpop()
{ assert( !isempty() );
return( the_stack[top++] ); }
bool isempty()
{ return( top == sz ); }
bool isfull()
{ return( top == 0 ); }
};

22-Mar-98

Page 3

C201/TAM