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

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

void main() {
Istack s1;
Cstack s3;
int i;

// a stack of integers // a stack of chars

s1.init(500); s3.init();

// default size of 100

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

for( i = 0; i < 20; i++ ) {
s3.push('a' + i);
// overloading push }
for( i = 0; i < 20; i++ ) {
cout << s3.pop() << ' ';
}
cout << endl;

}

The C++ compiler resolves which push and pop operators to use, based on the number and type of the parameters.

16-Mar-98

Page 8

C201/TAM/AGS