diff options
| author | verdant <i@glowisle.me> | 2026-05-24 20:23:46 +0800 |
|---|---|---|
| committer | verdant <i@glowisle.me> | 2026-05-24 20:23:46 +0800 |
| commit | f1c998ee2b201d7aa2ea3ff801cf1a03b4aa02fb (patch) | |
| tree | e8aaee1cfc34aaa91368875096f1522d01c5d813 /stack.c | |
| parent | b6fe9fc6a4f31d4fa0ddad7fdfd3324cd1c88d3e (diff) | |
| download | vmp-f1c998ee2b201d7aa2ea3ff801cf1a03b4aa02fb.tar.gz vmp-f1c998ee2b201d7aa2ea3ff801cf1a03b4aa02fb.zip | |
Use cmark instead of parse by hand
Diffstat (limited to 'stack.c')
| -rw-r--r-- | stack.c | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/stack.c b/stack.c deleted file mode 100644 index 1014785..0000000 --- a/stack.c +++ /dev/null @@ -1,65 +0,0 @@ -#include "./stack.h" -#include <stdbool.h> -#include <stdlib.h> - -bool stack_is_empty(stack *s) -{ - if (!s || s->top == -1) { - return true; - } - - return false; -} - -stack *new_stack(size_t size) -{ - stack *s = malloc(sizeof(stack)); - if (!s) - return NULL; - - s->data = malloc(size * sizeof(void *)); - if (!s->data) { - free(s); - return NULL; - } - - s->capacity = size; - s->top = -1; - return s; -} - -void free_stack(stack *s) -{ - if (!s) - return; - - free(s->data); - free(s); -} - -void *pop(stack *s) -{ - if (stack_is_empty(s)) - return NULL; - return s->data[s->top--]; -} - -void *peek(stack *s) -{ - if (stack_is_empty(s)) - return NULL; - return s->data[s->top]; -} - -void *push(stack *s, void *data) -{ - if (!s) - return NULL; - - if (s->top + 1 >= s->capacity) { - s->capacity *= 2; - s->data = realloc(s->data, sizeof(void *) * s->capacity); - } - - return s->data[++s->top] = data; -} |
