Write a Program to sort a list using Bubble sort ?
Answers
Answered by
4
Answer:
Bubble sort is one of the simplest sorting algorithms. The two adjacent elements of a list are checked and swapped if they are in wrong order and this process is repeated until we get a sorted list. The steps of performing a bubble sort are:
Compare the first and the second element of the list and swap them if they are in wrong order.
Compare the second and the third element of the list and swap them if they are in wrong order.
Proceed till the last element of the list in a similar fashion.
Repeat all of the above steps until the list is sorted.
Answered by
3
Answer:
lst = eval (input("Enter a list : "))
for i in range ( len ( lst ) - 1 ) :
if lst [ i ] > lst[ i + 1 ] :
lst [ i ] , lst [ i + 1 ] = lst[ i + 1 ] , lst [ i ]
print(lst)
Similar questions