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

Inline functions
#include <assert.h>
class Istack {
int sz;
int top;
int* stack;
public:
// Note the following are inline functions
void init(int Nitems = 100) {
sz = Nitems;
stack = new int[sz]; top = sz;
}
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 ); }
};

IMAGE imgs/lec-2001.gif

int* stack

16-Mar-98

Page 4

C201/TAM/AGS