Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions BubbleSort.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
n1=int(input("Enter Number 1:- "))
n2=int(input("Enter Number 2:- "))
n3=int(input("Enter Number 3:- "))
n4=int(input("Enter Number 4:- "))
n5=int(input("Enter Number 5:- "))
n6=int(input("Enter Number 6:- "))
n7=int(input("Enter Number 7:- "))
n8=int(input("Enter Number 8:- "))
n9=int(input("Enter Number 9:- "))
n10=int(input("Enter Number 10:- "))

a= [n1,n2,n3,n4,n5,n6,n7,n8,n9,n10]
count=0
for i in range(len(a)):
for j in range(1,len(a)):
if a[j-1] > a[j]:
count+=1
a[j-1],a[j]= a[j], a[j-1]
print(a)
print(f"The Total No. of times it was Swapped is {count}")
def bubble_sort(sort_list):
for j in range(len(sort_list)):
for k in range(len(sort_list) - 1):
if sort_list[k] > sort_list[k + 1]:
sort_list[k], sort_list[k + 1] = sort_list[k + 1], sort_list[k]
print(sort_list)


lst = []
size = int(input("Enter size of the list: \t"))

for i in range(size):
elements = int(input("Enter the element: \t"))
lst.append(elements)

bubble_sort(lst)
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@


This is a Simple Algorithm in Python Language which will Sort the given Numbers in assending order.
You have to give Number before running the program.
This Program takes user input for all the numbers that need to be sorted

This program does not takes User Input.