Created
November 20, 2013 15:48
-
-
Save Ex094/7565389 to your computer and use it in GitHub Desktop.
My Python Implementation of BubbleSort
This file contains hidden or 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(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