diff options
Diffstat (limited to 'src/stack.c')
| -rw-r--r-- | src/stack.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/stack.c b/src/stack.c new file mode 100644 index 0000000..e8e9bb1 --- /dev/null +++ b/src/stack.c @@ -0,0 +1,21 @@ +#include <stdio.h> +#include "stack.h" + +void stack_push(stack_t *stack, int value) +{ + if (stack->size >= stack->capacity) { + perror("stack overflow"); + exit(EXIT_FAILURE); + } + stack->data[stack->size++] = value; +} + +int stack_pop(stack_t *stack) +{ + if (stack->size <= 0) { + perror("stack_pop: Stack already empty"); + exit(EXIT_FAILURE); + } + return stack->data[--stack->size]; +} + |
