diff options
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 */ |
