Bubble Sort in DSA using Python

Program 1

#Implementation of bubble sort

import os
os.system('cls')
mylist=[]
n=int(input("Enter the limit: "))
print("Enter elements : ")
for i in range(n):
    x=int(input())
    mylist.append(x)

# Bubble Sort
for i in range(0,n):
    for j in range(0,n-i-1):
        if(mylist[j]>mylist[j+1]):
            mylist[j],mylist[j+1]=mylist[j+1],mylist[j]

print("Sorted elements : ")

print(mylist)

 

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *