home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_10_02 / 1002022a < prev    next >
Text File  |  1991-12-04  |  405b  |  28 lines

  1.  
  2.  
  3. #include <stdio.h>
  4.  
  5. #define STACK_TOP 50
  6.  
  7. static int stack[STACK_TOP];
  8. static size_t stack_ptr = 0;
  9.  
  10. void push(int value)
  11. {
  12.     if (stack_ptr < STACK_TOP)
  13.         stack[stack_ptr++] = value;
  14.     else
  15.         fprintf(stderr, "Stack full: discarding %d\n", value);
  16. }
  17.  
  18. int pop(void)
  19. {
  20.     if (stack_ptr > 0)
  21.         return stack[--stack_ptr];
  22.     else {
  23.         fprintf(stderr, "Stack empty\n");
  24.         return 0;
  25.     }
  26. }
  27.  
  28.