home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c021 / 7.img / EXAMPLES.ZIP / EX9.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-04  |  629 b   |  29 lines

  1. // ex9.cpp:   Using the print() virtual function
  2. // from Chapter 6 of Getting Started
  3. #include <iostream.h>
  4. #include "stack2.h"
  5.  
  6. main()
  7. {
  8.    Stack s(5);
  9.    List l, *lp;
  10.    int i = 0;
  11.  
  12.    // Insert the numbers 1 through 5 into the stack
  13.    while (s.push(i+1) == 0)
  14.       ++i;
  15.  
  16.    // Put a couple of numbers into the list
  17.    l.put_elem(1,0);
  18.    l.put_elem(2,1);
  19.    l.setn(2);
  20.  
  21.    cout << "Stack:\n";
  22.    lp = &s;           // line 22
  23.    lp->print();       // Invoke the Stack print() method; line 23
  24.  
  25.    cout << "\nList:\n";
  26.    lp = &l;
  27.    lp->print();       // Invoke the List print() method; line 27
  28. }
  29.