home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / tcpp / examples / stack2.cpp < prev    next >
C/C++ Source or Header  |  1990-06-09  |  499b  |  34 lines

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