TD4_DEV51_SAYEBABU/exo4.py

35 lines
835 B
Python
Raw Permalink Normal View History

2024-11-26 11:53:24 +01:00
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
2024-11-26 11:54:42 +01:00
# O(n²+n²)
# = O(n²)
2024-11-26 11:53:24 +01:00
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
2024-11-26 11:54:42 +01:00
#O(n²)
2024-11-26 11:53:24 +01:00
# testt
array = [[0, 3, 2], [9, 4, 5], [4, 1, 3]]
sorted_array = bublesort_multi_array(array)
print(sorted_array)