X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=TP_13%2Fexo1%2Flib%2Fsort.c;h=70a766b505773ba6e14823aef9b194c9c55c0b95;hb=c944d83b743f75264d017b47bc388962c51f2d3e;hp=aef713d8a69db4c9df3dddfda882d349ae06846b;hpb=33b9c6461d00f013d692dde3c3f79f0b002ce564;p=TD_C.git diff --git a/TP_13/exo1/lib/sort.c b/TP_13/exo1/lib/sort.c index aef713d..70a766b 100644 --- a/TP_13/exo1/lib/sort.c +++ b/TP_13/exo1/lib/sort.c @@ -9,19 +9,27 @@ 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_ptr(&array[i], &array[i+1]); - if (!rt) { rt = true; }; + swap_int(&array[i], &array[i+1]); + rt = true; } } return rt; } /* 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);