From ebfce98207ca8049c0a1e0130c85d107536dccf0 Mon Sep 17 00:00:00 2001 From: schied Date: Thu, 28 Nov 2024 22:47:42 +0100 Subject: [PATCH] Ajout de l'algorithme de tri --- sort_algorithm.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/sort_algorithm.py b/sort_algorithm.py index e69de29..851fd9f 100644 --- a/sort_algorithm.py +++ b/sort_algorithm.py @@ -0,0 +1,21 @@ +def sort_func(array): + if(not isinstance(array[0], list)): + for i in range(len(array)): + for j in range(0, len(array)-i-1): + if array[j] > array[j+1]: + array[j], array[j+1] = array[j+1], array[j] + return (array, [sum(array)]) + else: + res = [[], []] + for arr in array: + arrRes = sort_func(arr) + res[0].append(arrRes[0]) + res[1].append(arrRes[1][0]) + for i in range(len(res[0])-1): + if(res[1][i] > res[1][i+1]): + res[0][i], res[0][i+1] = res[0][i+1], res[0][i] + res[1][i], res[1][i+1] = res[1][i+1], res[1][i] + res[1] = [sum(res[1])] + return (res[0], res[1]) + +print(sort_func([[0,3,2], [9,4,5], [4,1,3]])[0]) \ No newline at end of file