Sort a list of elements using bubble sort algorithm.

Asked: Anonymously |Category: Python

def bubbleSort(lst):

n = len(lst)



for i in range(n-1):




for j in range(0, n-i-1):



if lst[j] > lst[j+1] :

lst[j], lst[j+1] = lst[j+1], lst[j]



lst = []



n = int(input("Enter number of elements : "))



for i in range(0, n):

ele = int(input())


lst.append(ele)


bubbleSort(lst)

print ("Sorted array is:")

for i in range(len(lst)):

print ("%d" %lst[i]),

4 views

Recent Posts

See All

"Believe you can and you're halfway there"