X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=TP_13%2Fexo1%2Flib%2Fsort.c;h=0bd005ed639c0921fcc0ecedab050a2df352137d;hb=0b8cccedf6a443a909844a480ab9b3c6908a073d;hp=f8917ea5ab6987bb96ccc9909f5bbdfa6f0d1cb8;hpb=cfdd46d2e85b05f77a03ae31f721e2fd4030996f;p=TD_C.git diff --git a/TP_13/exo1/lib/sort.c b/TP_13/exo1/lib/sort.c index f8917ea..0bd005e 100644 --- a/TP_13/exo1/lib/sort.c +++ b/TP_13/exo1/lib/sort.c @@ -1,6 +1,15 @@ #include "utils.h" #include "sort.h" +bool is_even(int a) { + return (a % 2 == 0); +} + +bool is_odd(int a) { + return (a % 2 != 0); + +} + bool ascending(int a, int b) { return a > b; } @@ -19,10 +28,10 @@ bool ascending_and_odd(int a, int b) { || ((a % 2 != 0) && (b % 2 != 0) && ascending(a, b))); } -static bool sort_first(int* array, unsigned length, criteria_cb criteria) { +static bool sort_first(int* array, unsigned length, s_criteria_cb sort_criteria) { bool rt = false; for (unsigned i = 0; i < length-1; i++) { - if (criteria(array[i], array[i+1])) { + if (sort_criteria(array[i], array[i+1])) { swap_int(&array[i], &array[i+1]); rt = true; } @@ -30,10 +39,10 @@ static bool sort_first(int* array, unsigned length, criteria_cb criteria) { return rt; } -/* this function is awaited in the array.c file */ -void sort_bubble_array(int* array, unsigned length, criteria_cb criteria) { +/* the feature of this function is awaited in the array.c file */ +void sort_bubble_array(int* array, unsigned length, s_criteria_cb sort_criteria) { bool rt; do { - rt = sort_first(array, length, criteria); + rt = sort_first(array, length, sort_criteria); } while (rt); }