summaryrefslogtreecommitdiffhomepage
path: root/examples/stack.c
blob: a60e556410bc37a5e6e15753e1ba7cd5dd226c23 (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

#include <stdio.h>
#include <stc/cstr.h>
#include <stc/cstack.h>

cdef_cvec(i, int);
cdef_cvec(c, char);
cdef_cstack(i, cvec_i);
cdef_cstack(c, cvec_c);

int main() {
    cstack_i stack = cstack_i_init();
    cstack_c chars = cstack_c_init();

    for (int i=0; i<100; ++i)
        cstack_i_push(&stack, i*i);
    
    for (int i=0; i<90; ++i)
        cstack_i_pop(&stack);
    
    c_foreach (i, cstack_i, stack)
        printf("%d\n", *cstack_i_itval(i));
    printf("top: %d\n", *cstack_i_top(&stack));
}