a = [1, 8, 3, 5, 7, 4]
for i in range(len(a), 0, -1):
for j in range(0, len(a) - 1):
if a[j] > a[j + 1]:
a[j], a[j + 1] = a[j + 1], a[j]
for i in range(len(a)-1, 0, -1):
swapped = False
for j in range(i):
if a[j] > a[j + 1]:
a[j], a[j + 1] = a[j + 1], a[j]
swapped = True
if not swapped:
break