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

#include <iostream.h> #include "mydefs2.h"

void main()
{
Istack s1,s2;
int i;

s1.init(500); s2.init();

// for the linked-list definition

for( i = 0; i < 20; i++ ) {
// add 21 items to s1
s1.push(i);
}

for( i = 0; i < 20; i++ ) {
// remove 21 items
cout << s1.pop() << ' '; }
cout << endl;

s2.push(10);
i = s2.pop();
assert (s2.isempty()); // confirm empty stack

}

* * *

Only one character different in the #include! s1 has been tested with 21 pops.
It correctly detects the empty stack, s2.

A linked list implementation of stack(Stack/stack2.cc) 16-Mar-98Page 2C201/TAM/AGS