+#include <stdio.h>
+#include <stdbool.h>
+
+typedef bool(*compare_cb)(int a, int b);
+
+bool ascending(int a, int b) {
+ return a > b;
+}
+
+bool descending(int a, int b) {
+ return a < b;
+}
+
+void swap(int* v1, int* v2) {
+ int tmp = *v1;
+ *v1 = *v2;
+ *v2 = tmp;
+}
+
+void displayArray(int* array, int count) {
+ for (int i = 0; i < count; i++) {
+ printf("Value in array at index[%d]= %d\n", i, array[i]);
+ }
+}
+
+bool sortFirst(int* array, int length, compare_cb compare) {
+ bool rt = false;
+ for (int i = 0; i < length-1; i++) {
+ if (compare(array[i], array[i+1])) {
+ swap(&array[i], &array[i+1]);
+ if (!rt) { rt = true; };
+ }
+ }
+ return rt;
+}
+
+void sortArray(int* array, int length, compare_cb compare) {
+ bool rt;
+ do {
+ rt = sortFirst(array, length, compare);
+ } while (rt);
+}
+
+int main() {
+ const int tab_size = 10;
+ int tab[10] = {4, 6, 2, 9, 5, 7, 1, 3, 8, 0};
+
+ printf("\nView array content unsorted:\n");
+ displayArray(tab, tab_size);
+ printf("\nNow, sorting the array ascending...\n");
+ sortArray(tab, tab_size, ascending);
+ printf("\nView array content sorted:\n");
+ displayArray(tab, tab_size);
+ printf("\nNow, sorting the array descending...\n");
+ sortArray(tab, tab_size, descending);
+ printf("\nView array content sorted:\n");
+ displayArray(tab, tab_size);
+
+ return 0;
+}