summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/new_pque.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-02-08 16:16:49 +0100
committerTyge Løvset <[email protected]>2023-02-08 17:18:24 +0100
commitc4441f5fc665194fbd7a894a67a64a08c3beac42 (patch)
tree82f231b6e8fcb75625166f98aa785baaa265a3d6 /misc/examples/new_pque.c
parent673dd5319a488d4b702b94dd9aeda4e497ae4fbc (diff)
downloadSTC-modified-c4441f5fc665194fbd7a894a67a64a08c3beac42.tar.gz
STC-modified-c4441f5fc665194fbd7a894a67a64a08c3beac42.zip
Changed to use lowercase flow-control macros in examples (uppercase will still be supported). Improved many examples to use c_make() to init containers.
Diffstat (limited to 'misc/examples/new_pque.c')
-rw-r--r--misc/examples/new_pque.c46
1 files changed, 8 insertions, 38 deletions
diff --git a/misc/examples/new_pque.c b/misc/examples/new_pque.c
index b3d94c2f..1442f376 100644
--- a/misc/examples/new_pque.c
+++ b/misc/examples/new_pque.c
@@ -1,55 +1,25 @@
#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_type PointQ
#define i_val Point
-#define i_cmp Point_cmp
-#define i_tag pnt
+#define i_less(a, b) a->x < b->x || a->x == b->x && a->y < b->y
#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)
+ c_auto (PointQ, 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});
+ pque = c_make(PointQ, {{23, 80}, {12, 32}, {54, 74}, {12, 62}});
+
// print
- while (!cpque_pnt_empty(&pque)) {
- const cpque_pnt_value *v = cpque_pnt_top(&pque);
+ for (; !PointQ_empty(&pque); PointQ_pop(&pque))
+ {
+ const Point *v = PointQ_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 (int i=0; i<cpque_int_size(&ique); ++i)
- printf(" %d", ique.data[i]);
- puts("");
- }
}