summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/vectors/stack.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc/examples/vectors/stack.c')
-rw-r--r--misc/examples/vectors/stack.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/misc/examples/vectors/stack.c b/misc/examples/vectors/stack.c
new file mode 100644
index 00000000..6297fb6f
--- /dev/null
+++ b/misc/examples/vectors/stack.c
@@ -0,0 +1,32 @@
+
+#include <stdio.h>
+
+#define i_tag i
+#define i_capacity 100
+#define i_key int
+#include <stc/cstack.h>
+
+#define i_tag c
+#define i_key char
+#include <stc/cstack.h>
+
+int main(void) {
+ cstack_i stack = {0};
+ cstack_c chars = {0};
+
+ c_forrange (i, 101)
+ cstack_i_push(&stack, (int)(i*i));
+
+ printf("%d\n", *cstack_i_top(&stack));
+
+ c_forrange (i, 90)
+ cstack_i_pop(&stack);
+
+ c_foreach (i, cstack_i, stack)
+ printf(" %d", *i.ref);
+ puts("");
+ printf("top: %d\n", *cstack_i_top(&stack));
+
+ cstack_i_drop(&stack);
+ cstack_c_drop(&chars);
+}