Created
February 5, 2018 16:38
-
-
Save edgan/3cea4c1979adbe75ae052d402ae9a892 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
[ngrennan@higgs ~] cat wtf1 | |
#!/usr/bin/python3 | |
def bubble_sort(L): | |
swap = False | |
while not swap: | |
swap = True | |
for j in range(1, len(L)): | |
if L[j-1] > L[j]: | |
swap = False | |
temp = L[j] | |
L[j] = L[j-1] | |
L[j-1] = temp | |
return L | |
L = [2, 6, 7, 10, 3, 5, 4, 1, 9, 8] | |
print(bubble_sort(L)) | |
[ngrennan@higgs ~] ./wtf1 | |
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |
Author
edgan
commented
Feb 5, 2018
[ngrennan@higgs ~] cat ./not-wtf3
#!/usr/bin/python3
def bubbleSort(alist):
for i in range(len(alist)-1):
for i in range(len(alist)-1):
if alist[i] > alist[i+1]:
alist[i], alist[i+1] = alist[i+1], alist[i]
L = [2, 6, 7, 10, 3, 5, 4, 1, 9, 8]
bubbleSort(L)
print(L)
[ngrennan@higgs ~] ./not-wtf3
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment