+#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);
+}