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())



print ("Sorted array is:")

for i in range(len(lst)):

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

5 views0 comments

Recent Posts

See All

Binary string reduction in Python

Asked: Sudeep |Category: Python x=int(input("Enter the value of x : ")) for i in range(x): n=int(input("Enter the value of n : ")) y=input("Enter the value of y : ") l=list(y) k=0

"Believe you can and you're halfway there"