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

  1. // stack.cpp:     Implementation of the Stack class
  2.  
  3. #include <iostream.h>
  4. #include "stack2.h"
  5.  
  6. int Stack::push(int elem)
  7. {
  8.    if (top < nmax)
  9.    {
  10.       list[top++] = elem;
  11.       return 0;
  12.    }
  13.    else
  14.       return -1;
  15. }
  16.  
  17. int Stack::pop(int& elem)
  18. {
  19.    if (top > 0)
  20.    {
  21.       elem = list[--top];
  22.       return 0;
  23.    }
  24.    else
  25.       return -1;
  26. }
  27.  
  28. void Stack::print()
  29. {
  30.    for (int i = top-1; i >= 0; --i)
  31.       cout << list[i] << "\n";
  32. }
  33.