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

For the function that uses vstack(Reverse.cc) #include <iostream.h>
#include "Vstack.h"
// Reverse does not know about A_stack or L_stack // but it does require the data type to be
<int>

void reverse( Gstack<int> &s, int n ) {
int i;

for( i = 0; i < n; i++ ) {
s.push(i);
}
for( i = 0; i < n; i++ ) {
cout << s.pop() << ' '; }
cout << endl;

}

A program that uses reverse
#include "Vstack.h"
#include "Linkstack.h"
#include "Arraystack.h"

extern void reverse( Gstack<int> &s, int n );

void main() {
Array_stack
<int>s1(500);
Link_stack
<int> s2;// or s2(137);
Array_stack<char>s3;// not used, but created
Link_stack
<char>s4(50);// not used, but created

reverse (s1, 20);
reverse (s2, 20);
reverse (s3, 20);//reverse only knows about integers reverse (s4, 20);//need more generality, see later?

// // }

22-Mar-98

Page 6

C201/TAM