(arr)
| 24 | |
| 25 | |
| 26 | def bubbleSort(arr): |
| 27 | n = len(arr) |
| 28 | |
| 29 | # Traverse through all array elements |
| 30 | for i in range(n): |
| 31 | not_swap = True |
| 32 | # Last i elements are already in place |
| 33 | for j in range(0, n - i - 1): |
| 34 | # traverse the array from 0 to n-i-1 |
| 35 | # Swap if the element found is greater |
| 36 | # than the next element |
| 37 | if arr[j] > arr[j + 1]: |
| 38 | arr[j], arr[j + 1] = arr[j + 1], arr[j] |
| 39 | not_swap = False |
| 40 | if not_swap: |
| 41 | break |
| 42 | |
| 43 | |
| 44 | # Driver code to test above |