Bubble Sort Program in Python
Sort the given set of number in order using Bubble Sort in Python...
Input:
How many numbers you have to sort
n = 5
get input as 5 number in a set is
list = [10, 50,20,15,5]
Output:
Sorted array is:
5 10 15 20 50
Program:
for python 3...
n = int(input())
lis = []
for i in range(n):
k = int(input())
lis.append(k)
for i in range(len(lis)):
for j in range(0, len(lis)-i-1):
if lis[j] > lis[j+1]:
lis[j], lis[j+1] = lis[j+1], lis[j]
print ("Sorted array is:")
for i in range(len(lis)):
print (lis[i],end=" ")
-------------------------------------------------
Comments
Post a Comment