repositories
/
TD_C.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Move callback functions into the same file
[TD_C.git]
/
TP_13
/
exo1
/
lib
/
sort.c
diff --git
a/TP_13/exo1/lib/sort.c
b/TP_13/exo1/lib/sort.c
index 70a766b505773ba6e14823aef9b194c9c55c0b95..0bd005ed639c0921fcc0ecedab050a2df352137d 100644
(file)
--- a/
TP_13/exo1/lib/sort.c
+++ b/
TP_13/exo1/lib/sort.c
@@
-1,6
+1,15
@@
#include "utils.h"
#include "sort.h"
#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;
}
bool ascending(int a, int b) {
return a > b;
}
@@
-10,17
+19,19
@@
bool descending(int a, int b) {
}
bool ascending_and_even(int a, int b) {
}
bool ascending_and_even(int a, int b) {
- return (ascending(a, b) && (a % 2 == 0));
+ return (((a % 2 != 0) && (b % 2 == 0)) || ((a % 2 == 0) && (b % 2 == 0) && ascending(a, b)) \
+ || ((a % 2 != 0) && (b % 2 != 0) && ascending(a, b)));
}
bool ascending_and_odd(int a, int b) {
}
bool ascending_and_odd(int a, int b) {
- return (ascending(a, b) && (a % 2 != 0));
+ return (((a % 2 == 0) && (b % 2 != 0)) || ((a % 2 == 0) && (b % 2 == 0) && ascending(a, 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++) {
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;
}
swap_int(&array[i], &array[i+1]);
rt = true;
}
@@
-28,10
+39,10
@@
static bool sort_first(int* array, unsigned length, criteria_cb criteria) {
return rt;
}
return rt;
}
-/* this function is awaited in the array.c file */
-void sort_bubble_array(int* array, unsigned length,
criteria_cb
criteria) {
+/* th
e feature of th
is function is awaited in the array.c file */
+void sort_bubble_array(int* array, unsigned length,
s_criteria_cb sort_
criteria) {
bool rt;
do {
bool rt;
do {
- rt = sort_first(array, length, criteria);
+ rt = sort_first(array, length,
sort_
criteria);
} while (rt);
}
} while (rt);
}