Created
January 21, 2022 14:42
-
-
Save gerep/2d144baa198df56e4a01f69baab3099a to your computer and use it in GitHub Desktop.
Bubble sort
This file contains 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(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