summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/stack.c
diff options
context:
space:
mode:
authorTyge Lovset <[email protected]>2022-12-20 23:31:51 +0100
committerTyge Lovset <[email protected]>2022-12-20 23:31:51 +0100
commit5f57d597cd27aef55adbcb3b452973b0c6e33667 (patch)
treedfd59c2fd0e36a6ef37912a9d0cc5a65970f1524 /misc/examples/stack.c
parent1763be8c8cbbc0896477fcf924edd4180d1345a9 (diff)
downloadSTC-modified-5f57d597cd27aef55adbcb3b452973b0c6e33667.tar.gz
STC-modified-5f57d597cd27aef55adbcb3b452973b0c6e33667.zip
Restructured folders: examples, benchmarks, tests into misc folder.
Diffstat (limited to 'misc/examples/stack.c')
-rw-r--r--misc/examples/stack.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/misc/examples/stack.c b/misc/examples/stack.c
new file mode 100644
index 00000000..a6a4a492
--- /dev/null
+++ b/misc/examples/stack.c
@@ -0,0 +1,30 @@
+
+#include <stdio.h>
+
+#define i_tag i
+#define i_capacity 100
+#define i_val int
+#include <stc/cstack.h>
+
+#define i_tag c
+#define i_val char
+#include <stc/cstack.h>
+
+int main() {
+ c_auto (cstack_i, stack)
+ c_auto (cstack_c, chars)
+ {
+ c_forrange (i, 101)
+ cstack_i_push(&stack, 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));
+ }
+}