Skip to content

Instantly share code, notes, and snippets.

@wilcoln
Created March 10, 2018 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilcoln/b31235e713b38dac6f3e01b9a580dcf6 to your computer and use it in GitHub Desktop.
Save wilcoln/b31235e713b38dac6f3e01b9a580dcf6 to your computer and use it in GitHub Desktop.
Python bubble sort code
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
@wilcoln
Copy link
Author

wilcoln commented Mar 10, 2018

This version of the bubble sort algorithm relies on a boolean flag, here named "permutation"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment