Graphics;
Click Here
def b_s(n):
l=[]
for i in range(n):
num=int(input("enter the number:"))
l.append(num)
#bubble sort
for k in range(0,n,1):
for j in range(0,n-1,1):
if l[j]>l[j+1]:
t=l[j]
l[j]=l[j+1]
l[j+1]=t
print("Stage=",k+1,"inside list=",j+1,"=",l)
print("Stage=",k+1,"Final list=",l)
print("Final Result list=:",l)
#main program
n=int(input("enter size of list:"))
print("size of list:",n)
b_s(n)
Input
enter size of list:5
size of list: 5
enter the number:5
enter the number:2
enter the number:7
enter the number:10
enter the number:1
Output
Stage= 1 inside list= 1 = [2, 5, 7, 10, 1]
Stage= 1 inside list= 2 = [2, 5, 7, 10, 1]
Stage= 1 inside list= 3 = [2, 5, 7, 10, 1]
Stage= 1 inside list= 4 = [2, 5, 7, 1, 10]
Stage= 1 Final list= [2, 5, 7, 1, 10]
Stage= 2 inside list= 1 = [2, 5, 7, 1, 10]
Stage= 2 inside list= 2 = [2, 5, 7, 1, 10]
Stage= 2 inside list= 3 = [2, 5, 1, 7, 10]
Stage= 2 inside list= 4 = [2, 5, 1, 7, 10]
Stage= 2 Final list= [2, 5, 1, 7, 10]
Stage= 3 inside list= 1 = [2, 5, 1, 7, 10]
Stage= 3 inside list= 2 = [2, 1, 5, 7, 10]
Stage= 3 inside list= 3 = [2, 1, 5, 7, 10]
Stage= 3 inside list= 4 = [2, 1, 5, 7, 10]
Stage= 3 Final list= [2, 1, 5, 7, 10]
Stage= 4 inside list= 1 = [1, 2, 5, 7, 10]
Stage= 4 inside list= 2 = [1, 2, 5, 7, 10]
Stage= 4 inside list= 3 = [1, 2, 5, 7, 10]
Stage= 4 inside list= 4 = [1, 2, 5, 7, 10]
Stage= 4 Final list= [1, 2, 5, 7, 10]
Stage= 5 inside list= 1 = [1, 2, 5, 7, 10]
Stage= 5 inside list= 2 = [1, 2, 5, 7, 10]
Stage= 5 inside list= 3 = [1, 2, 5, 7, 10]
Stage= 5 inside list= 4 = [1, 2, 5, 7, 10]
Stage= 5 Final list= [1, 2, 5, 7, 10]
Final Result list=: [1, 2, 5, 7, 10]
Input
enter size of list:5
size of list: 5
enter the number: 6
enter the number: 5
enter the number: 4
enter the number: 3
enter the number: 1
Output
Stage= 1 inside list= 1 = [5, 6, 4, 3, 1]
Stage= 1 inside list= 2 = [5, 4, 6, 3, 1]
Stage= 1 inside list= 3 = [5, 4, 3, 6, 1]
Stage= 1 inside list= 4 = [5, 4, 3, 1, 6]
Stage= 1 Final list= [5, 4, 3, 1, 6]
Stage= 2 inside list= 1 = [4, 5, 3, 1, 6]
Stage= 2 inside list= 2 = [4, 3, 5, 1, 6]
Stage= 2 inside list= 3 = [4, 3, 1, 5, 6]
Stage= 2 inside list= 4 = [4, 3, 1, 5, 6]
Stage= 2 Final list= [4, 3, 1, 5, 6]
Stage= 3 inside list= 1 = [3, 4, 1, 5, 6]
Stage= 3 inside list= 2 = [3, 1, 4, 5, 6]
Stage= 3 inside list= 3 = [3, 1, 4, 5, 6]
Stage= 3 inside list= 4 = [3, 1, 4, 5, 6]
Stage= 3 Final list= [3, 1, 4, 5, 6]
Stage= 4 inside list= 1 = [1, 3, 4, 5, 6]
Stage= 4 inside list= 2 = [1, 3, 4, 5, 6]
Stage= 4 inside list= 3 = [1, 3, 4, 5, 6]
Stage= 4 inside list= 4 = [1, 3, 4, 5, 6]
Stage= 4 Final list= [1, 3, 4, 5, 6]
Stage= 5 inside list= 1 = [1, 3, 4, 5, 6]
Stage= 5 inside list= 2 = [1, 3, 4, 5, 6]
Stage= 5 inside list= 3 = [1, 3, 4, 5, 6]
Stage= 5 inside list= 4 = [1, 3, 4, 5, 6]
Stage= 5 Final list= [1, 3, 4, 5, 6]
Final Result list=: [1, 3, 4, 5, 6]
>>>