Skip to content

Instantly share code, notes, and snippets.

@thelinuxpoint
Last active September 23, 2022 07:59
Show Gist options
  • Save thelinuxpoint/e83e85572b961ec9928861d3702e809d to your computer and use it in GitHub Desktop.
Save thelinuxpoint/e83e85572b961ec9928861d3702e809d to your computer and use it in GitHub Desktop.
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