diff --git a/rendu.md b/rendu.md new file mode 100644 index 0000000..7c27e4f --- /dev/null +++ b/rendu.md @@ -0,0 +1,14 @@ +# Exercice 2 + +function_1(tableau1, tableau2) : Complexité O(n*m) ou n est la longueur de tableau1 et m la longueur du tableau2 + +function_2(x) : Complexité de 0(x) + +function_3(x) : Complexité de O(1) + + + + + + + diff --git a/tri.py b/tri.py new file mode 100644 index 0000000..d1462c0 --- /dev/null +++ b/tri.py @@ -0,0 +1,42 @@ +tab = [ + [7, 1, 4], + [9, 3, 0], + [2, 6, 10], + [5, 2, 1], + [0, 8, 7], + [4, 9, 3], + [1, 0, 6], + [10, 5, 2], + [3, 7, 8], + [6, 4, 9], + [8, 2, 5], + [0, 3, 1], + [7, 10, 4], + [9, 6, 0], + [5, 8, 3], + [2, 1, 7], + [4, 0, 9], + [3, 5, 6], + [10, 7, 2], + [1, 8, 4] +] + + +def tri(tableau): + x = 0 + valueTab = {} + for subTab in tableau : + sum = 0 + subTab.sort() + for value in subTab: + sum = sum + value + valueTab[x] = sum + x = x + 1 + newValueTab = dict(sorted(valueTab.items(), key=lambda item: item[1])) + newTab = [] + for key in newValueTab: + newTab.append(tableau[key]) + return newTab + +print(tri(tab)) +