dos_compilers/Borland Turbo C++ v1/EXAMPLES/EX9.CPP
2024-07-02 07:34:51 -07:00

29 lines
627 B
C++
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ex9.cpp: Using the print() virtual function
// from Chapter 6 of User's Guide
#include <iostream.h>
#include "stack2.h"
main()
{
Stack s(5);
List l, *lp;
int i = 0;
// Insert the numbers 1 through 5 into the stack
while (s.push(i+1) == 0)
++i;
// Put a couple of numbers into the list
l.put_elem(1,0);
l.put_elem(2,1);
l.setn(2);
cout << "Stack:\n";
lp = &s; // line 22
lp->print(); // Invoke the Stack print() method; line 23
cout << "\nList:\n";
lp = &l;
lp->print(); // Invoke the List print() method; line 27
}