def bubble_sort(collection):
def swap(i, j):
tmp = collection[j]
collection[j] = collection[i]
collection[i] = tmp
n = len(collection)
swapped = True
x = -1
while swapped:
swapped = False
x += 1
for i in range(1, n - x):
if collection[i - 1] > collection[i]:
swap(i - 1, i)
swapped = True
return collection
Complexity:
‣