return el_count;
}
-unsigned count_tab_criteria(int tab[], unsigned tab_size, count_criteria_cb c_criteria) {
+unsigned count_tab_criteria(int tab[], unsigned tab_size, c_criteria_cb c_criteria) {
unsigned cr_count = 0;
for (unsigned i = 0; i < tab_size; i++) {
}
-void sort_tab(int tab[], unsigned tab_size, criteria_cb criteria) {
- sort_bubble_array(tab, tab_size, criteria);
+void sort_tab(int tab[], unsigned tab_size, s_criteria_cb sort_criteria) {
+ sort_bubble_array(tab, tab_size, sort_criteria);
}
#include "sort.h"
-typedef bool(*count_criteria_cb)(int a);
+typedef bool(*c_criteria_cb)(int a);
bool is_even(int a);
bool is_odd(int a);
int* concat_tab(int tab1[], unsigned tab_size1, int tab2[], unsigned tab_size2);
int* resize_tab(int tab[], unsigned old_tab_size, unsigned new_tab_size);
unsigned count_tab_element(int tab[], unsigned tab_size, int element);
-unsigned count_tab_criteria(int tab[], unsigned tab_size, count_criteria_cb c_criteria);
-void sort_tab(int tab[], unsigned tab_size, criteria_cb criteria);
+unsigned count_tab_criteria(int tab[], unsigned tab_size, c_criteria_cb c_criteria);
+void sort_tab(int tab[], unsigned tab_size, s_criteria_cb sort_criteria);
#endif /* ARRAY_H */
int errno = 0;
int choice = 0;
bool done = false;
- criteria_cb criteria;
+ s_criteria_cb sort_criteria;
printf("\n=== Menu de tri ===\n\n");
printf("1) Croissant.\n");
} while (!done);
switch (choice) {
case 1:
- criteria = ascending;
+ sort_criteria = ascending;
break;
case 2:
- criteria = descending;
+ sort_criteria = descending;
break;
case 3:
- criteria = ascending_and_even;
+ sort_criteria = ascending_and_even;
break;
case 4:
- criteria = ascending_and_odd;
+ sort_criteria = ascending_and_odd;
break;
default:
/* sort ascending by default, unused code path */
- criteria = ascending;
+ sort_criteria = ascending;
break;
}
- sort_tab(array, size, criteria);
+ sort_tab(array, size, sort_criteria);
}
void do_count(int array[], unsigned size) {
errno = prompt_value("\nNouvelle taille?", (int*)&new_size);
handle_prompt_error(errno);
+ /* FIXME: one should able the set the array new content if new_size > *old_size
+ * for now, new values are zeroed */
array = resize_tab(array, *old_size, new_size);
*old_size = new_size;
}
|| ((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;
}
}
/* the feature of this function is awaited in the array.c file */
-void sort_bubble_array(int* array, unsigned length, criteria_cb criteria) {
+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);
}
#include <stdbool.h>
-typedef bool(*criteria_cb)(int a, int b);
+typedef bool(*s_criteria_cb)(int a, int b);
/* sort criteria */
bool ascending(int a, int b);
bool ascending_and_even(int a, int b);
bool ascending_and_odd(int a, int b);
-void sort_bubble_array(int* array, unsigned length, criteria_cb criteria);
+void sort_bubble_array(int* array, unsigned length, s_criteria_cb sort_criteria);
#endif /* SORT_H */