#define ARRAY_H
+
#endif /* ARRAY_H */
+#include <stdio.h>
+
+#include "io.h"
+
+int prompt_value(const char* msg, int* result) {
+ puts(msg);
+ int retVal = scanf("%d", result);
+ return (retVal == 1) ? 0 : 1;
+}
+
+void display_array(int* array, int size) {
+ for (int i = 0; i < size; i++) {
+ printf("value in array at index[%d]=%d\n", i, array[i]);
+ }
+}
#ifndef IO_H
#define IO_H
+int prompt_value(const char* msg, int* result);
+void display_array(int* array, int size);
#endif /* IO_H */
+#include "utils.h"
+#include "sort.h"
+
+bool ascending(int a, int b) {
+ return a > b;
+}
+
+bool descending(int a, int b) {
+ return a < b;
+}
+
+static bool sort_first(int* array, int length, criteria_cb criteria) {
+ bool rt = false;
+ for (int 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; };
+ }
+ }
+ return rt;
+}
+
+/* this function is awaited in the array.c file */
+void sort_array(int* array, int length, criteria_cb criteria) {
+ bool rt;
+ do {
+ rt = sort_first(array, length, criteria);
+ } while (rt);
+}
#ifndef SORT_H
#define SORT_H
+#include <stdbool.h>
+
+typedef bool(*criteria_cb)(int a, int b);
+
+/* sort criteria */
+bool ascending(int a, int b);
+bool descending(int a, int b);
+
+void sort_array(int* array, int length, criteria_cb criteria);
#endif /* SORT_H */
--- /dev/null
+#include "utils.h"
+
+void swap_int_ptr(int* v1, int* v2) {
+ int tmp = *v1;
+ *v1 = *v2;
+ *v2 = tmp;
+}
+
+void swap_ptr(void* v1, void* v2) {
+ void* tmp = v1;
+ v1 = v2;
+ v2 = tmp;
+}
--- /dev/null
+#ifndef UTILS_H
+#define UTILS_H
+
+void swap_int_ptr(int* v1, int* v2);
+void swap_ptr(void* v1, void* v2);
+
+#endif /* UTILS_H */