Bubble Sort
Sort the given numbers using bubble sort
Input:
How many numbers you have to sort
n=4
input=[78,54,66,70,77]
,
Output:
sorted array is:
54 66 70 77 78
Program:
n = int (input())
list=[]
for i in range(n):
k=int (input())
list . append(k)
for i in range(len (list) ):
for j in range(0, len (list)-i-1):
if list[j] > list[j+1]:
list[j].list[j+1]=list[j+1].list[j]
print("Sorted array is:")
for I in range(len(list)):
printf(list[i],ends=" ")
Input:
How many numbers you have to sort
n=4
input=[78,54,66,70,77]
,
Output:
sorted array is:
54 66 70 77 78
Program:
n = int (input())
list=[]
for i in range(n):
k=int (input())
list . append(k)
for i in range(len (list) ):
for j in range(0, len (list)-i-1):
if list[j] > list[j+1]:
list[j].list[j+1]=list[j+1].list[j]
print("Sorted array is:")
for I in range(len(list)):
printf(list[i],ends=" ")
Comments
Post a Comment