summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/new_pque.c
blob: 2bb1d729d5c63abe6ebc09f114381613210aca2b (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>

#define i_val int
#include <stc/cstack.h>
#define i_val int
#include <stc/cpque.h>

struct Point { int x, y; } typedef Point;

int Point_cmp(const Point* a, const Point* b) {
    int c = a->x - b->x;
    return c ? c : a->y - b->y;
}

#define i_val Point
#define i_cmp Point_cmp
#define i_tag pnt
#include <stc/cpque.h>


int main()
{
    c_auto (cstack_int, istk)
    {
        cstack_int_push(&istk, 123);
        cstack_int_push(&istk, 321);
        // print
        c_foreach (i, cstack_int, istk)
            printf(" %d", *i.ref);
        puts("");
    }
    c_auto (cpque_pnt, pque)
    {
        cpque_pnt_push(&pque, (Point){23, 80});
        cpque_pnt_push(&pque, (Point){12, 32});
        cpque_pnt_push(&pque, (Point){54, 74});
        cpque_pnt_push(&pque, (Point){12, 62});
        // print
        while (!cpque_pnt_empty(&pque)) {
            const cpque_pnt_value *v = cpque_pnt_top(&pque);
            printf(" (%d,%d)", v->x, v->y);
            cpque_pnt_pop(&pque);
        }
        puts("");
    }
    c_auto (cpque_int, ique)
    {
        cpque_int_push(&ique, 123);
        cpque_int_push(&ique, 321);
        // print
        for (size_t i=0; i<cpque_int_size(&ique); ++i)
            printf(" %d", ique.data[i]);
        puts("");
    }
}