Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include "mystack.h"
- void push(Stack *S, char val)
- {
- S->v[ (S->top)++ ] = val;
- }
- char pop(Stack *S)
- {
- return (S->v[ --(S->top) ]);
- }
- char showtop(Stack *S)
- {
- return (S->v[ S->top - 1]);
- }
- void init(Stack *S)
- {
- S->top = 0;
- }
- int empty(Stack *S)
- {
- return (S->top == 0);
- }
- void StackPrint(Stack *S)
- {
- int i;
- if (S->top == 0)
- printf("Stack is empty.\n");
- else
- {
- printf("Stack contents: ");
- for (i = 0; i < S->top; i++)
- {
- printf("%d ", S->v[i]);
- }
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment