Last active
September 23, 2022 07:59
-
-
Save thelinuxpoint/e83e85572b961ec9928861d3702e809d to your computer and use it in GitHub Desktop.
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 bubbleSort(array): | |
for i in range(len(array)): | |
# track of swapping | |
swapped = False | |
for j in range(0, len(array) - i - 1): | |
# compare two adjacent elements | |
if array[j] > array[j + 1]: | |
# swapping occurs | |
temp = array[j] | |
array[j] = array[j+1] | |
array[j+1] = temp | |
swapped = True | |
if not swapped: | |
break | |
data = [ 5, 3, 1, 2, 4, 0 ] | |
bubbleSort(data) | |
print('Sorted Array in Ascending Order:') | |
print(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment