1 2 3 4 5 6 7 8 9 10 11

Declaring the public interface

class Istack {
int sz; // stack size
int top;// location of top element
int* stack;// pointer to origin of stack
public:
// Prototype access functions
void init (int Nitems = 100);
void push (int x);
int pop ();
bool isempty();
bool isfull();
};

IMAGE imgs/lec-1901.gif

int* stack

Note

*classes look a lot like structs. In fact, C++ treats structs as a class whose members are by default public

*

by default, members of classes are private. We could say private before int sz, if we wanted to be explicit

See also class handout, with variations on a theme, and discussion.

March 14, 1998

Page 9

C201/TAM