Skip to content

Instantly share code, notes, and snippets.

@ioanzicu
Created August 1, 2022 14:38
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 ioanzicu/a2429f2db07264b90ae44e1cda7bbba7 to your computer and use it in GitHub Desktop.
Save ioanzicu/a2429f2db07264b90ae44e1cda7bbba7 to your computer and use it in GitHub Desktop.
Bubble Sort implementation in Python 3.
def bubble_sort(arr):
for i in range(len(arr)):
is_sorted = False
for j in range(i, len(arr)):
if arr[i] > arr[j]:
temp = arr[j]
arr[j] = arr[i]
arr[i] = temp
if is_sorted:
break
return arr
nums = [3, 4, 711, 2, 5, 9, 0, 6, 7]
result = bubble_sort(nums)
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment