Ajout de l'algorithme de tri

This commit is contained in:
Killian SCHIED 2024-11-28 22:47:42 +01:00
parent 3e0f1ff007
commit ebfce98207

View File

@ -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])