t1nman

mystack.c

May 22nd, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "mystack.h"
  3.  
  4. void push(Stack *S, char val)
  5. {
  6.     S->v[ (S->top)++ ] = val;
  7. }
  8.  
  9. char pop(Stack *S)
  10. {
  11.     return (S->v[ --(S->top) ]);
  12. }
  13.  
  14. char showtop(Stack *S)
  15. {
  16.     return (S->v[ S->top - 1]);
  17. }
  18.  
  19. void init(Stack *S)
  20. {
  21.     S->top = 0;
  22. }
  23.  
  24. int empty(Stack *S)
  25. {
  26.     return (S->top == 0);
  27. }
  28.  
  29. void StackPrint(Stack *S)
  30. {
  31.     int i;
  32.     if (S->top == 0)
  33.         printf("Stack is empty.\n");
  34.     else
  35.     {
  36.         printf("Stack contents: ");
  37.         for (i = 0; i < S->top; i++)
  38.         {
  39.             printf("%d ", S->v[i]);
  40.         }
  41.         printf("\n");
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment