Here is how bubble sort works in Python.
Run the code here: https://repl.it/@VinitKhandelwal/bubblesort
Run the code here: https://repl.it/@VinitKhandelwal/bubblesort
def bubblesort(list1):
a = len(list1)
for i in range(0, a-1):
for j in range(0, a-1):
if list1[j] > list1[j+1]:
temp = list1[j]
list1[j] = list1[j+1]
list1[j+1] = temp
a -= 1
return list1
print(bubblesort([7,1,4,8,6,5,2,3,9,0]))
Comments
Post a Comment