Skip to content

Instantly share code, notes, and snippets.

@gerep
Created January 21, 2022 14:42
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 gerep/2d144baa198df56e4a01f69baab3099a to your computer and use it in GitHub Desktop.
Save gerep/2d144baa198df56e4a01f69baab3099a to your computer and use it in GitHub Desktop.
Bubble sort
def bubble_sort(nums):
n = len(nums)
swap = True # required to start the while loop
while swap:
swap = False # always defaults to False
for i in range(1, n):
if nums[i-1] > nums[i]:
nums[i-1], nums[i] = nums[i], nums[i-1]
swap = True
return nums
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment