mirror of
https://github.com/Fare-spec/cours.git
synced 2025-12-08 03:00:37 +00:00
formatte file
This commit is contained in:
@@ -8,9 +8,10 @@ def partition(tab, debut, fin):
|
||||
tab[i + 1], tab[fin] = tab[fin], tab[i + 1]
|
||||
return i + 1
|
||||
|
||||
|
||||
def fusion(tab, debut, milieu, fin):
|
||||
gauche = tab[debut:milieu + 1]
|
||||
droite = tab[milieu + 1:fin + 1]
|
||||
gauche = tab[debut : milieu + 1]
|
||||
droite = tab[milieu + 1 : fin + 1]
|
||||
i, j, k = 0, 0, debut
|
||||
|
||||
while i < len(gauche) and j < len(droite):
|
||||
@@ -32,6 +33,7 @@ def fusion(tab, debut, milieu, fin):
|
||||
j += 1
|
||||
k += 1
|
||||
|
||||
|
||||
def tri_fusion_partition(tab, debut, fin):
|
||||
if debut < fin:
|
||||
pivot_index = partition(tab, debut, fin)
|
||||
@@ -39,7 +41,7 @@ def tri_fusion_partition(tab, debut, fin):
|
||||
tri_fusion_partition(tab, pivot_index + 1, fin)
|
||||
fusion(tab, debut, pivot_index, fin)
|
||||
|
||||
|
||||
tableau = [34, 7, 23, 32, 5, 62, 32, 8, 9]
|
||||
tri_fusion_partition(tableau, 0, len(tableau) - 1)
|
||||
print("Tableau trié :", tableau)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user