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 / STACK.CPP < prev    next >
C/C++ Source or Header  |  1992-02-18  |  648b  |  41 lines

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