#include <stdio.h>
#include "io.h"
+#include "array.h"
int prompt_value(const char* msg, int* result) {
puts(msg);
return (retVal == 1) ? 0 : 1;
}
+int* prompt_array(int array[], unsigned* size) {
+ int errno = prompt_value("Taille du tableau?", (int*)size);
+ array = create_tab(array, *size);
+ for (unsigned i = 0; i < *size; i++) {
+ errno += prompt_value("Valeur?", &array[i]);
+ }
+ if (errno == 0) {
+ return array;
+ } else {
+ return NULL;
+ }
+}
+
void display_array(int* array, int size) {
- printf("--array begin--\n");
- for (int i = 0; i < size; i++) {
- printf("value in array at index[%d]=%d\n", i, array[i]);
+ if (array != NULL) {
+ printf("--array begin--\n");
+ for (int i = 0; i < size; i++) {
+ printf("value in array at index[%d]=%d\n", i, array[i]);
+ }
+ printf("--array end--\n");
+ } else {
+ printf("--array NULL--\n");
}
- printf("--array end--\n");
}
#define IO_H
int prompt_value(const char* msg, int* result);
+int* prompt_array(int array[], unsigned* size);
void display_array(int* array, int size);
}
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) {
- 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) {
int main() {
int* tab = NULL;
- unsigned tab_size = 11;
- tab = create_tab(tab, tab_size);
+ unsigned tab_size = 0;
+
+ tab = prompt_array(tab, &tab_size);
printf("%d\n", tab_size);
display_array(tab, tab_size);
- tab_size = 20;
- tab = resize_tab(tab, tab_size);
-
- printf("%d\n", tab_size);
+ sort_tab(tab, tab_size, ascending_and_odd);
display_array(tab, tab_size);