Bubble sort in Python
def bubble_sort(lst):
for i in range(len(lst)):
for j in range(len(lst)-1-i):
if(lst[j]>lst[j+1]):
temp = lst[j]
lst[j]=lst[j+1]
lst[j+1]=temp
print(lst)
lst = [90,65,12,98,31,20,89,71,90]
bubble_sort(lst)
for i in range(len(lst)):
for j in range(len(lst)-1-i):
if(lst[j]>lst[j+1]):
temp = lst[j]
lst[j]=lst[j+1]
lst[j+1]=temp
print(lst)
lst = [90,65,12,98,31,20,89,71,90]
bubble_sort(lst)
Comments
Post a Comment