Skip to content

Instantly share code, notes, and snippets.

@Ex094
Created November 20, 2013 15:48
Show Gist options
  • Save Ex094/7565389 to your computer and use it in GitHub Desktop.
Save Ex094/7565389 to your computer and use it in GitHub Desktop.
My Python Implementation of BubbleSort
def bubblesort(items):
length = len(items) - 1 #Length of the list to be sorted
swapped = False #Swapping set to False as Default
while swapped != True:
for i in range(0, length):
if items[i] > items[i + 1]: //Compare the adjacent Items
a,b = items.index(items[i]), items.index(items[i + 1]) //Stores the items index number for swap
items[b], items[a] = items[a], items[b] //Swaps the items place
print(items) //Prints the swapped condition
swapped = True //Repeat
pass
swapped = False
pass
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment