summaryrefslogtreecommitdiff
path: root/graphs/piscine/quick_sort
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:08:27 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:08:27 +0200
commitc9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch)
tree3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /graphs/piscine/quick_sort
add: graphs et rushs
Diffstat (limited to 'graphs/piscine/quick_sort')
-rw-r--r--graphs/piscine/quick_sort/quick_sort.c18
-rw-r--r--graphs/piscine/quick_sort/quick_sort_example.c19
2 files changed, 37 insertions, 0 deletions
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 <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/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 <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;
+}