Created
June 10, 2017 16:38
-
-
Save mverleg/9ffe16f4eff5963f87a3fd5dbb30a529 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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