1 2 3 4 5 6 7 8 9 10 11

The main thing about Istack

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

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

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

// Default, 100 cells

for ( i = 0; i < 20; i++ ) {
s1.push(i);
}
// try putting 501 elements!

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

// pop and print

s2.push(10);// Push a 10 onto s2 i = s2.pop();// Take it off into i
// try s2.pop();here

}

Note:
*It is short!
*Tested by pushing 501 things onto s1 and by adding
another s2.pop() before exiting
*The (correct) output is:

19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 *If we forget to call init, we are in big trouble *We haven't provided a way to get rid of the stack
we don't have a destructor

March 14, 1998

Page 11

C201/TAM