0
def bubble_sort(list):
for i in range(len(list)):
for j in range(len(list)-1):
if list[j] > list[j+1]:
list[j], list[j+1] = list[j+1], list[j]
else:
continue
I just made this Bubble Sort, but I just realized that it makes some unnecessary interactions because of the is greater(i), I wonder how to stop all interactions when the list is sorted / know when the list will be sorted
The
range
should go from 0 to 0i - 1
. Then you’d have a good optimization. And theelse
is really unnecessary =)– Jefferson Quesado
I think this answer is worth reading: https://answall.com/a/311812/64969
– Jefferson Quesado
I tested in 2 lists but only worked in one, in the other still lacked a value in the middle to be ordered
– Angelo Gonçalves Salles