TP 13 exo1: Rename the integer values swap function
[TD_C.git] / TP_13 / exo1 / lib / sort.c
CommitLineData
33b9c646
JB
1#include "utils.h"
2#include "sort.h"
3
4bool ascending(int a, int b) {
5 return a > b;
6}
7
8bool descending(int a, int b) {
9 return a < b;
10}
11
12static bool sort_first(int* array, int length, criteria_cb criteria) {
13 bool rt = false;
14 for (int i = 0; i < length-1; i++) {
15 if (criteria(array[i], array[i+1])) {
0139cafd 16 swap_int(&array[i], &array[i+1]);
33b9c646
JB
17 if (!rt) { rt = true; };
18 }
19 }
20 return rt;
21}
22
23/* this function is awaited in the array.c file */
24void sort_array(int* array, int length, criteria_cb criteria) {
25 bool rt;
26 do {
27 rt = sort_first(array, length, criteria);
28 } while (rt);
29}