diff options
Diffstat (limited to 'example/stack.c')
| -rw-r--r-- | example/stack.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/example/stack.c b/example/stack.c index 93128f4..d5d2e5a 100644 --- a/example/stack.c +++ b/example/stack.c @@ -1,20 +1,27 @@ +// stack.c - Example usage of stack.h dynamic stack + +#include <stdio.h> + typedef double stack_value_t; #define STACK_IMPLEMENTATION #include "../include/stack.h" -void main() { - stack_t stack = { .capacity = 10 }; - stack_init(&stack); +int main(void) { + stack_t stack = {0}; + stack.capacity = 10; + stack_init(&stack); + + for (int i = 0; i < 15; i++) { + stack_push(&stack, (stack_value_t)i); + } + + printf("%lf\n", stack_peek(&stack)); + printf("%lf\n", stack_pop(&stack)); - for(int i = 0; i < 15; i++) { - stack_push(&stack, (stack_value_t) i); - } - - printf("%lf\n", stack_peek(&stack)); + for (int i = 0; i < 14; i++) { printf("%lf\n", stack_pop(&stack)); + } - for(int i = 0; i < 15; i++) { - printf("%lf\n", stack_pop(&stack)); - } + stack_free(&stack); }
\ No newline at end of file |