summaryrefslogtreecommitdiffstats
path: root/example/stack.c
diff options
context:
space:
mode:
authorEthan Werner <mail@ethanwerner.com>2026-06-09 01:17:41 +0400
committerEthan Werner <mail@ethanwerner.com>2026-06-09 01:17:41 +0400
commit96ecf29e8be977f51f351308ef2c7c492bb829aa (patch)
treec664aa61262e6f7627a732f0e4fbb84281b99952 /example/stack.c
parentf6a144987cc403de8ad6bddd055f756120f8d405 (diff)
refactor
Diffstat (limited to 'example/stack.c')
-rw-r--r--example/stack.c29
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