From 977ddbd80452a1ad4d8dcd6f005fdb2ffd490a7e Mon Sep 17 00:00:00 2001 From: Jean-Luc NELET Date: Wed, 27 Nov 2024 19:09:55 +0100 Subject: [PATCH] Exo 4 tri fonctionnel? --- Exo4Tri.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Exo4Tri.py diff --git a/Exo4Tri.py b/Exo4Tri.py new file mode 100644 index 0000000..3d68094 --- /dev/null +++ b/Exo4Tri.py @@ -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)