1 2 3 4 5 6 7 8 9 10 11

The Stack ADT

Ignoring how you implement lists, what sorts of things do you want to do?

*

*

*

*

*

void init (stack S, unsigned int Nitems)

void push (stack S, item x)

item pop (stack S)

bool isempty (stack S)

bool isfull (stack S)

In the best of all possible worlds, you would like to be able to declare things to be of type STACK and ITEM, then choose at the last possible moment (perhaps when you are linking your final program together) which implementation to use.

This is precisely what ADTs are about.

For now, let's assume all items in the stack are integers. (We'll make our ADT more general when we cover the use of templates.)

March 14, 1998

Page 8

C201/TAM