summaryrefslogtreecommitdiff
path: root/simclist-1.5/examples/ex3.c
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2025-08-09 08:35:03 +0200
committerAldrik Ramaekers <aldrikboy@gmail.com>2025-08-09 08:35:03 +0200
commit432f24319319fe040e142059eb83279c53f90ab8 (patch)
tree5631eb0eb3a46d086070e8398d9080ff681133ac /simclist-1.5/examples/ex3.c
parent5d34aff5888d3f0c624251f15bedb96c347978d6 (diff)
refactor 2
Diffstat (limited to 'simclist-1.5/examples/ex3.c')
-rw-r--r--simclist-1.5/examples/ex3.c58
1 files changed, 0 insertions, 58 deletions
diff --git a/simclist-1.5/examples/ex3.c b/simclist-1.5/examples/ex3.c
deleted file mode 100644
index 74d3091..0000000
--- a/simclist-1.5/examples/ex3.c
+++ /dev/null
@@ -1,58 +0,0 @@
-#include <stdio.h>
-
-#include <simclist.h>
-
-typedef struct {
- int x, y;
-} point2D;
-
-typedef struct {
- point2D a, b, c, d;
-} rectangle; /* custom data type to store in list */
-
-/* this function returns the size of elements */
-size_t mymeter(const void *el) {
- /* every element has the constant size of a rectangle structure */
- return sizeof(rectangle);
-}
-
-/*
- * compare rectangles by area
- *
- * this function compares two elements:
- * <0: a greater than b
- * 0: a equivalent to b
- * >0: b greater than a
- */
-int mycomparator(const void *a, const void *b) {
- /* compare areas */
- const rectangle *A = (rectangle *) a;
- const rectangle *B = (rectangle *) b;
- unsigned int areaA, areaB;
- areaA = ((A->c.y - A->b.y) * (A->b.x - A->a.x));
- areaB = ((B->c.y - B->b.y) * (B->b.x - B->a.x));
- return (areaA < areaB) - (areaA > areaB);
-}
-
-int main() {
- rectangle rect;
- list_t l;
-
- list_init(&l);
-
- /* setting the custom spanning function */
- list_attributes_copy(&l, mymeter, 1);
-
- /* acquire rectangles and insert in list ... */
-
- /* setting the custom area comparator */
- list_attributes_comparator(&l, mycomparator);
- list_sort(&l, -1); /* sorting by area (descending) */
-
- /* [display list ...] */
-
- list_destroy(&l);
-
- return 0;
-}
-