diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
| commit | c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch) | |
| tree | 3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /rushs/tinyprintf/bubble_sort | |
add: graphs et rushs
Diffstat (limited to 'rushs/tinyprintf/bubble_sort')
| -rw-r--r-- | rushs/tinyprintf/bubble_sort/bubble_sort.c | 25 | ||||
| -rw-r--r-- | rushs/tinyprintf/bubble_sort/bubble_sort.h | 8 |
2 files changed, 33 insertions, 0 deletions
diff --git a/rushs/tinyprintf/bubble_sort/bubble_sort.c b/rushs/tinyprintf/bubble_sort/bubble_sort.c new file mode 100644 index 0000000..13d2ba3 --- /dev/null +++ b/rushs/tinyprintf/bubble_sort/bubble_sort.c @@ -0,0 +1,25 @@ +#include "bubble_sort.h" + +void bubble_sort(int array[], size_t size) +{ + if (!array || size == 0) + { + return; + } + + int mod; + do + { + mod = 0; + for (size_t i = 0; i < size - 1; i++) + { + if (array[i] > array[i + 1]) + { + mod = 1; + int tmp = array[i]; + array[i] = array[i + 1]; + array[i + 1] = tmp; + } + } + } while (mod); +} diff --git a/rushs/tinyprintf/bubble_sort/bubble_sort.h b/rushs/tinyprintf/bubble_sort/bubble_sort.h new file mode 100644 index 0000000..a33d531 --- /dev/null +++ b/rushs/tinyprintf/bubble_sort/bubble_sort.h @@ -0,0 +1,8 @@ +#ifndef BUBBLE_SORT_H +#define BUBBLE_SORT_H + +#include <stddef.h> + +void bubble_sort(int array[], size_t size); + +#endif /* !BUBBLE_SORT_H */ |
