Skip to content

Instantly share code, notes, and snippets.

@thedeveloperr
Created January 14, 2017 14:30
Show Gist options
  • Save thedeveloperr/1ea37dec057b46d191bb8eac4ffd239f to your computer and use it in GitHub Desktop.
Save thedeveloperr/1ea37dec057b46d191bb8eac4ffd239f to your computer and use it in GitHub Desktop.
Bubble sort python implementation
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