forked from menault/TD4_DEV51_Qualite_Algo
35 lines
835 B
Python
35 lines
835 B
Python
def bublesort_multi_array(array):
|
|
for subarray in array:
|
|
sort_bubble_array(subarray)
|
|
swap = 1
|
|
while (swap > 0):
|
|
swap = 0
|
|
for i in range(1,len(array)):
|
|
if sum(array[i-1])>sum(array[i]):
|
|
temp = array[i-1]
|
|
array[i-1]= array[i]
|
|
array[i] = temp
|
|
swap += 1
|
|
return array
|
|
# O(n²+n²)
|
|
# = O(n²)
|
|
|
|
def sort_bubble_array(array): #merci votre td1
|
|
swap = 1
|
|
while (swap > 0):
|
|
swap = 0
|
|
for i in range(1,len(array)):
|
|
if array[i-1]>array[i]:
|
|
temp = array[i-1]
|
|
array[i-1]= array[i]
|
|
array[i] = temp
|
|
swap += 1
|
|
#O(n²)
|
|
|
|
# testt
|
|
array = [[0, 3, 2], [9, 4, 5], [4, 1, 3]]
|
|
sorted_array = bublesort_multi_array(array)
|
|
print(sorted_array)
|
|
|
|
|