Created
August 4, 2013 20:49
-
-
Save emre/6151887 to your computer and use it in GitHub Desktop.
bubble sort
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 bubble_sort(unsorted_list): | |
| """ | |
| bonus: http://www.youtube.com/watch?v=u_tKnsG0rVs | |
| >>> unsorted_list = [2, 1, 9, 8, 89] | |
| >>> bubble_sort(unsorted_list) | |
| >>> unsorted_list | |
| [1, 2, 8, 9, 89] | |
| """ | |
| end = len(unsorted_list) - 1 | |
| while end != 0: | |
| for i in range(end): | |
| if unsorted_list[i] > unsorted_list[i + 1]: | |
| unsorted_list[i + 1], unsorted_list[i] = unsorted_list[i], unsorted_list[i + 1] | |
| end -= 1 | |
| if __name__ == '__main__': | |
| import doctest | |
| doctest.testmod() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment