Created
March 10, 2018 19:17
-
-
Save wilcoln/b31235e713b38dac6f3e01b9a580dcf6 to your computer and use it in GitHub Desktop.
Python bubble sort code
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 bubble(tab): | |
permutation = True | |
while(permutation): | |
permutation = False | |
for i in range(0,len(tab)-1): | |
if(tab[i] > tab[i+1]): | |
tmp = tab[i] | |
tab[i] = tab[i+1] | |
tab[i+1] = tmp | |
permutation = True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This version of the bubble sort algorithm relies on a boolean flag, here named "permutation"