Back to SDS/2 Parametric Scripts
# bubblesort.py
a = [4, 17, 6, 2,
19, 33, 77, 44, 21, 7, 5, 3]
print a
def bubblesort(a):
for swap in range(len(a)-1, 0, -1):
for index in
range(swap):
if
a[index] > a[index + 1]:
a[index],
a[index + 1] = a[index + 1], a[index]
return a
a = bubblesort(a)
print a
"""
>>> [4, 17,
6, 2, 19, 33, 77, 44, 21, 7, 5, 3]
[2, 3, 4, 5, 6, 7,
17, 19, 21, 33, 44, 77]
"""