summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/stack.c
blob: 86099607fc580047be389a0478c68ee3adf23636 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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, (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));
    }
}