home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / TCPP30-3.ZIP / EXAMPLES.ZIP / STACK2.CPP < prev    next >
C/C++ Source or Header  |  1992-02-18  |  557b  |  36 lines

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