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

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

void main()
{
Array_stack
<int>s1(500);// was Astack
Array_stack
<char>s3;// was Cstack
int i;
// remainder the same
for( i = 0; i < 20; i++ ) {
s1.push(i);
}
for( i = 0; i < 20; i++ ) {
cout << s1.pop() << ' ';
}
cout << endl;

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

}

Object Oriented Programming support:

inheritanceand virtualfunctions.
One of the promises made for C++ was that you could put off implementation choices to the very end. We are now going to declare a pure virtual class called
Vstack, two derivations (arrays and linked lists), a main program that declares stacks of both types and passes them one at a time to a function that has no idea which type of stack it is getting. Indeed it handles an Array_stack at the first call and a Link_stack (a linked list of nodes) on the second.

22-Mar-98

Page 2

C201/TAM