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

C++ uses special member functions based on the name of the class. For Istackthe constructor would be called
Istack :: Istack
and the destructor would be called
Istack :: ~Istack

#include <assert.h>

class Istack {
int sz;
int top;
int* stack;
public:
Istack(int Nitems = 100){
// The constructors
sz = Nitems; stack = new int[sz]; top = sz;
}
~Istack()
{ delete[] stack; }
// delete[] deletes arrays
void push(int x) {
assert( !isfull() ); stack[--top] = x;
}
int pop() {
assert( !isempty() ); return( stack[top++] );
}
bool isempty()
{ return( top == sz ); }
bool isfull()
{ return( top == 0 ); }
};

16-Mar-98

Page 10

C201/TAM/AGS