Skip to content

Instantly share code, notes, and snippets.

@mverleg
Created June 10, 2017 16:38
Show Gist options
  • Save mverleg/9ffe16f4eff5963f87a3fd5dbb30a529 to your computer and use it in GitHub Desktop.
Save mverleg/9ffe16f4eff5963f87a3fd5dbb30a529 to your computer and use it in GitHub Desktop.
from random import shuffle, seed
seed(12345)
x = list(range(10))
shuffle(x)
print(x)
def bubble_sort(z):
z2 = bubble_step(z)
if z == z2:
return z2
return bubble_sort(z2)
def bubble_step(y):
if len(y) <= 1:
return y
if y[0] < y[1]:
return [y[0]] + bubble_step(y[1:])
else:
return [y[1]] + bubble_step([y[0]] + y[2:])
print(bubble_sort(x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment