Skip to content

Instantly share code, notes, and snippets.

@samg11
Created January 1, 2021 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samg11/27d589d1ad7e055c82189f9d9edef326 to your computer and use it in GitHub Desktop.
Save samg11/27d589d1ad7e055c82189f9d9edef326 to your computer and use it in GitHub Desktop.
An implementation of bubble sort in python
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