-
-
Save reterVision/9a10eabee5d288586096 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
| """ | |
| Bubble Sort | |
| """ | |
| def bubble_sort(l): | |
| i = 0 | |
| while i < len(l): | |
| j = i + 1 | |
| while j < len(l): | |
| if l[i] > l[j]: | |
| l[i], l[j] = l[j], l[i] | |
| j += 1 | |
| i += 1 | |
| return l | |
| if __name__ == "__main__": | |
| test_list = [7, 5, 6, 3, 2, 1, 9, 8, 10] | |
| print bubble_sort(test_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment