forked from menault/TD4_DEV51_Qualite_Algo
Exo 4 tri fonctionnel?
This commit is contained in:
parent
1b37a3ec15
commit
977ddbd804
25
Exo4Tri.py
Normal file
25
Exo4Tri.py
Normal file
@ -0,0 +1,25 @@
|
||||
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)
|
Loading…
Reference in New Issue
Block a user