From cb84498028880f2eca88890b563246a723b8739e Mon Sep 17 00:00:00 2001 From: Spectre Date: Wed, 4 Dec 2024 09:50:29 +0100 Subject: [PATCH] quick_sort --- fonctions_tri/partitionement.py | 60 +++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 fonctions_tri/partitionement.py diff --git a/fonctions_tri/partitionement.py b/fonctions_tri/partitionement.py new file mode 100644 index 0000000..a23604c --- /dev/null +++ b/fonctions_tri/partitionement.py @@ -0,0 +1,60 @@ +from typing import Any + +def partitionement(liste: list[Any],debut,fin): + pivot = liste[debut] + gauche = debut + 1 + droite = fin - 1 + while gauche <= droite: + while (gauche <= droite) and (liste[gauche] <= pivot): + gauche += 1 + + while (gauche <= droite) and (liste[droite] > pivot): + droite -= 1 + + if gauche < droite: + exchange(liste,gauche,droite) + gauche += 1 + droite -= 1 + exchange(liste,droite,debut) + return droite + + +def exchange(liste, indx_g, indx_d): + liste[indx_g],liste[indx_d] = liste[indx_d], liste[indx_g] + + +l = [12,4,0,44,27] +print(partitionement(l,0,len(l)-1)) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +