Created
January 1, 2021 00:55
-
-
Save samg11/27d589d1ad7e055c82189f9d9edef326 to your computer and use it in GitHub Desktop.
An implementation of bubble sort in python
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 sort(arr): | |
arrLen = len(arr) | |
times_sorted = 0 | |
for _ in range(arrLen): | |
for i in range(arrLen - times_sorted): | |
if i < arrLen-1: | |
if arr[i] > arr[i+1]: | |
a = arr[i] | |
b = arr[i+1] | |
arr[i] = b | |
arr[i+1] = a | |
times_sorted += 1 | |
return arr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment