forked from menault/TD4_DEV51_Qualite_Algo
32 lines
749 B
Python
32 lines
749 B
Python
def sort_array(array):
|
|
def selection_sort(lst):
|
|
n = len(lst)
|
|
for i in range(n):
|
|
min_idx = i
|
|
for j in range(i+1, n):
|
|
if lst[j] < lst[min_idx]:
|
|
min_idx = j
|
|
lst[i], lst[min_idx] = lst[min_idx], lst[i]
|
|
return lst
|
|
|
|
for i in range(len(array)):
|
|
array[i] = selection_sort(array[i])
|
|
|
|
n = len(array)
|
|
for i in range(n):
|
|
for j in range(i+1, n):
|
|
if sum(array[i]) > sum(array[j]):
|
|
array[i], array[j] = array[j], array[i]
|
|
|
|
return array
|
|
|
|
# Test
|
|
array = [
|
|
[0, 3, 2],
|
|
[9, 4, 5],
|
|
[4, 1, 3]
|
|
]
|
|
|
|
sorted_array = sort_array(array)
|
|
print("Tableau trié :", sorted_array)
|