Skip to content

Instantly share code, notes, and snippets.

@prakash-pun
Last active June 26, 2021 06:30
Show Gist options
  • Save prakash-pun/f777d1cec350c2eece74da97da13a739 to your computer and use it in GitHub Desktop.
Save prakash-pun/f777d1cec350c2eece74da97da13a739 to your computer and use it in GitHub Desktop.
Bubble Sort Algorithm
# Bubble sort algorithm
def bubbleSort(dataset):
# TODO: start with the array length and decrement each time
for i in range(len(dataset) -1, 0, -1):
for j in range(i):
if dataset[j] > dataset [j+1]:
temp = dataset[j]
dataset[j] = dataset[j+1]
dataset[j+1] = temp
print("Current state: ", dataset)
def main():
list1 = [1,30,20,4,19,43,34,54]
bubbleSort(list1)
print("Result: ",list1)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment