From c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:08:27 +0200 Subject: add: graphs et rushs --- rushs/tinyprintf/selection_sort/selection_sort.c | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 rushs/tinyprintf/selection_sort/selection_sort.c (limited to 'rushs/tinyprintf/selection_sort') diff --git a/rushs/tinyprintf/selection_sort/selection_sort.c b/rushs/tinyprintf/selection_sort/selection_sort.c new file mode 100644 index 0000000..98adc7e --- /dev/null +++ b/rushs/tinyprintf/selection_sort/selection_sort.c @@ -0,0 +1,30 @@ +#include + +void swap(int *a, int *b) +{ + int tmp = *a; + *a = *b; + *b = tmp; +} + +unsigned array_min(const int arr[], unsigned start, unsigned size) +{ + unsigned min = start; + for (; start < size; start++) + { + if (arr[min] > arr[start]) + { + min = start; + } + } + return min; +} + +void selection_sort(int arr[], unsigned size) +{ + for (size_t i = 0; i < size; i++) + { + unsigned j = array_min(arr, i, size); + swap(&(arr[i]), &(arr[j])); + } +} -- cgit v1.2.3