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 --- graphs/piscine/quick_sort/quick_sort.c | 18 ++++++++++++++++++ graphs/piscine/quick_sort/quick_sort_example.c | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 graphs/piscine/quick_sort/quick_sort.c create mode 100644 graphs/piscine/quick_sort/quick_sort_example.c (limited to 'graphs/piscine/quick_sort') diff --git a/graphs/piscine/quick_sort/quick_sort.c b/graphs/piscine/quick_sort/quick_sort.c new file mode 100644 index 0000000..6c61fc3 --- /dev/null +++ b/graphs/piscine/quick_sort/quick_sort.c @@ -0,0 +1,18 @@ +#include + +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/graphs/piscine/quick_sort/quick_sort_example.c b/graphs/piscine/quick_sort/quick_sort_example.c new file mode 100644 index 0000000..2a5228f --- /dev/null +++ b/graphs/piscine/quick_sort/quick_sort_example.c @@ -0,0 +1,19 @@ +#include + +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; +} -- cgit v1.2.3