Created
August 1, 2022 14:38
-
-
Save ioanzicu/a2429f2db07264b90ae44e1cda7bbba7 to your computer and use it in GitHub Desktop.
Bubble Sort implementation in Python 3.
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(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