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 ); }
};
|