forked from menault/TD4_DEV51_Qualite_Algo
26 lines
794 B
Python
26 lines
794 B
Python
def tri_par_selection(tableau):
|
|
n = len(tableau)
|
|
for i in range(n):
|
|
min_index = i
|
|
for j in range(i + 1, n):
|
|
if tableau[j] < tableau[min_index]:
|
|
min_index = j
|
|
tableau[i], tableau[min_index] = tableau[min_index], tableau[i]
|
|
return tableau
|
|
|
|
def triJL(tableau):
|
|
for i in range(len(tableau)):
|
|
tableau[i] = tri_par_selection(tableau[i])
|
|
|
|
for i in range(len(tableau)):
|
|
for j in range(i + 1, len(tableau)):
|
|
if sum(tableau[j]) < sum(tableau[i]):
|
|
tableau[i], tableau[j] = tableau[j], tableau[i]
|
|
|
|
return tableau
|
|
|
|
tableau = [[0, 3, 2], [9, 4, 5], [4, 1, 3]]
|
|
print("tableau avant triage : ", tableau)
|
|
resultat = triJL(tableau)
|
|
print("Tableau trié :", resultat)
|