diff options
Diffstat (limited to 'misc/examples/new_pque.c')
| -rw-r--r-- | misc/examples/new_pque.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/misc/examples/new_pque.c b/misc/examples/new_pque.c new file mode 100644 index 00000000..2bb1d729 --- /dev/null +++ b/misc/examples/new_pque.c @@ -0,0 +1,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(""); + } +} |
