home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_10_04 / 1004094b < prev    next >
Text File  |  1992-02-10  |  726b  |  50 lines

  1.  
  2. void push1(int value)
  3. {
  4.     if (stack_ptr1 > stack_ptr2)
  5.         printf("Stack 1 is full\n");
  6.     else
  7.         stack[stack_ptr1++] = value;
  8. }
  9.  
  10. void push2(int value)
  11. {
  12.     if (stack_ptr1 > stack_ptr2)
  13.         printf("Stack 2 is full\n");
  14.     else
  15.         stack[stack_ptr2--] = value;
  16. }
  17.  
  18. int pop1(void)
  19. {
  20.     if (stack_ptr1 == 0) {
  21.         printf("Stack 1 is empty\n");
  22.         return 0;
  23.     }
  24.  
  25.     return stack[--stack_ptr1];
  26. }
  27.  
  28. int pop2(void)
  29. {
  30.     if (stack_ptr2 == STACK_SIZE - 1) {
  31.         printf("Stack 2 is empty\n");
  32.         return 0;
  33.     }
  34.  
  35.     return stack[++stack_ptr2];
  36. }
  37.  
  38. void dump_stack(void)
  39. {
  40.     int i;
  41.  
  42.     printf("Stack contains: ");
  43.     for (i = 0; i < STACK_SIZE; ++i)
  44.         printf("%4d", stack[i]);
  45.  
  46.     printf("\tsp1 = %lu, sp2 = %lu\n",
  47.         (unsigned long)stack_ptr1, (unsigned long)stack_ptr2);
  48. }
  49.  
  50.