diff options
Diffstat (limited to 'rushs/tinyprintf/quick_sort')
| -rw-r--r-- | rushs/tinyprintf/quick_sort/quick_sort.c | 18 | ||||
| -rw-r--r-- | rushs/tinyprintf/quick_sort/quick_sort_example.c | 19 |
2 files changed, 37 insertions, 0 deletions
diff --git a/rushs/tinyprintf/quick_sort/quick_sort.c b/rushs/tinyprintf/quick_sort/quick_sort.c new file mode 100644 index 0000000..6c61fc3 --- /dev/null +++ b/rushs/tinyprintf/quick_sort/quick_sort.c @@ -0,0 +1,18 @@ +#include <stddef.h> + +void quicksort(int *tab, size_t len) +{ + if (tab == NULL) + { + return; + } + for (size_t i = 1; i < len; i++) + { + for (size_t j = i; j > 0 && tab[j - 1] > tab[j]; j--) + { + int tmp = tab[j]; + tab[j] = tab[j - 1]; + tab[j - 1] = tmp; + } + } +} diff --git a/rushs/tinyprintf/quick_sort/quick_sort_example.c b/rushs/tinyprintf/quick_sort/quick_sort_example.c new file mode 100644 index 0000000..2a5228f --- /dev/null +++ b/rushs/tinyprintf/quick_sort/quick_sort_example.c @@ -0,0 +1,19 @@ +#include <stdio.h> + +void quicksort(int *tab, int len); + +int main(void) +{ + unsigned i = 0; + int tab[] = { 10, 11, 2, 3, 8, 5, 7, 6, 26, 30, 2, 1, 17, 13, 14 }; + + unsigned size = sizeof(tab) / sizeof(int); + + quicksort(tab, size); + + for (; i < size - 1; ++i) + printf("%d ", tab[i]); + printf("%d\n", tab[i]); + + return 0; +} |
