Created
January 16, 2017 14:34
-
-
Save peroon/dd0137d9ee046a735ed4e5e97854f384 to your computer and use it in GitHub Desktop.
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(arr): | |
| n = len(arr) | |
| total_swap = 0 | |
| for i in xrange(n): | |
| numberOfSwaps = 0 | |
| for j in xrange(n - 1): | |
| if arr[j] > arr[j + 1]: | |
| arr[j], arr[j + 1] = arr[j + 1], arr[j] | |
| numberOfSwaps += 1 | |
| total_swap += 1 | |
| if numberOfSwaps == 0: | |
| break | |
| return total_swap |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
大きい値が泡のように上に上がっていく