add cxListReverse()

Tue, 28 Dec 2021 17:41:51 +0100

author
Mike Becker <universe@uap-core.de>
date
Tue, 28 Dec 2021 17:41:51 +0100
changeset 490
e66551b47466
parent 489
af6be1e123aa
child 491
6d538177f746

add cxListReverse()

src/cx/list.h file | annotate | diff | comparison | revisions
src/linked_list.c file | annotate | diff | comparison | revisions
--- a/src/cx/list.h	Tue Dec 28 17:38:02 2021 +0100
+++ b/src/cx/list.h	Tue Dec 28 17:41:51 2021 +0100
@@ -114,6 +114,11 @@
             cx_list_s const *list,
             cx_list_s const *other
     );
+
+    /**
+     * Member function for reversing the order of the items.
+     */
+    void (*reverse)(cx_list_s *list);
 } cx_list_class;
 
 /**
@@ -249,6 +254,15 @@
 }
 
 /**
+ * Reverses the order of the items.
+ *
+ * @param list the list
+ */
+static inline void cxListReverse(CxList list) {
+    list->cl->reverse(list);
+}
+
+/**
  * Compares a list to another list of the same type.
  *
  * First, the list sizes are compared. If they match, the lists are compared element-wise.
--- a/src/linked_list.c	Tue Dec 28 17:38:02 2021 +0100
+++ b/src/linked_list.c	Tue Dec 28 17:41:51 2021 +0100
@@ -613,6 +613,11 @@
                         true, list->cmpfunc);
 }
 
+static void cx_ll_reverse(cx_list_s *list) {
+    cx_linked_list *ll = (cx_linked_list *) list;
+    cx_linked_list_reverse((void **) &ll->begin, (void **) ll->end, CX_LL_LOC_PREV, CX_LL_LOC_NEXT);
+}
+
 static int cx_ll_compare(
         cx_list_s const *list,
         cx_list_s const *other
@@ -642,7 +647,8 @@
         cx_ll_at,
         cx_ll_find,
         cx_ll_sort,
-        cx_ll_compare
+        cx_ll_compare,
+        cx_ll_reverse
 };
 
 static cx_list_class cx_pointer_linked_list_class = {
@@ -652,7 +658,8 @@
         cx_pll_at,
         cx_pll_find,
         cx_pll_sort,
-        cx_pll_compare
+        cx_pll_compare,
+        cx_ll_reverse
 };
 
 CxList cxLinkedListCreate(

mercurial