diff options
| author | Johnny Richard <johnny@johnnyrichard.com> | 2025-04-11 01:15:01 +0200 |
|---|---|---|
| committer | Johnny Richard <johnny@johnnyrichard.com> | 2025-04-14 23:11:22 +0200 |
| commit | e7f69c8fbbbcbddde84933b2becd91e787d1ac63 (patch) | |
| tree | 16cd17da17133494dd06aab614724e76b059d4ad /src/stack.c | |
Intial commit
Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
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]; +} + |
