top of page
Click here to go to the home page of AskTheCode.

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]),

Recent Posts

See All

댓글


bottom of page