Created
January 14, 2017 14:30
-
-
Save thedeveloperr/1ea37dec057b46d191bb8eac4ffd239f to your computer and use it in GitHub Desktop.
Bubble sort python implementation
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
def bubbleSort(l): | |
for n in range(len(l),1,-1): | |
no_switch = 0 | |
for i in range(0,n-1): | |
if l[i] > l[i+1]: | |
l[i], l[i+1] = l[i+1], l[i] | |
switch+=1 | |
if no_switch == 0: | |
break | |
egList = [1,2,3,4,5,6,7,8,9,10] | |
bubbleSort(egList) | |
print(egList) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment