TP 13 exo1: Add more library functions
[TD_C.git] / TP_13 / exo1 / lib / sort.c
index 8b196ffe3c6662ad1ec687a117ec09ca0bd70943..0fdb0be30c6ef0c087d8088dc2f3afdc0c0ca18d 100644 (file)
@@ -9,9 +9,17 @@ bool descending(int a, int b) {
     return a < b;
 }
 
-static bool sort_first(int* array, int length, criteria_cb criteria) {
+bool ascending_and_even(int a, int b) {
+    return (ascending(a, b) && (a % 2 == 0));
+}
+
+bool ascending_and_odd(int a, int b) {
+    return (ascending(a, b) && (a % 2 != 0));
+}
+
+static bool sort_first(int* array, unsigned length, criteria_cb criteria) {
     bool rt = false;
-    for (int i = 0; i < length-1; i++) {
+    for (unsigned i = 0; i < length-1; i++) {
         if (criteria(array[i], array[i+1])) {
             swap_int(&array[i], &array[i+1]);
             if (!rt) { rt = true; };
@@ -21,7 +29,7 @@ static bool sort_first(int* array, int length, criteria_cb criteria) {
 }
 
 /* this function is awaited in the array.c file */
-void sort_array(int* array, int length, criteria_cb criteria) {
+void sort_bubble_array(int* array, unsigned length, criteria_cb criteria) {
     bool rt;
     do {
         rt = sort_first(array, length, criteria);