Computer Science, asked by sarithprasadpb8ojr, 9 months ago

Write a Program to sort a list using Bubble sort ?

Answers

Answered by utkarsh6032
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 prakharagrawal6055
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