* Comparing to other programming languages like C, C++, Java.. Python is the most simplest and easy language.
* Python is very simple and easy for doing programs comparable to other programming languages.
* In most of the programming languages the Bubble Sort program takes lots of steps to execute it, but in Python it is very simple to execute it within few steps.
Concept of Bubble Sort:
* Bubble sort is the simplest sorting algorithm that sorts the given set of numbers into ascending or decending order.
* It works by repetedly swapping the adjacent elements if they are in the wrong order.
Python Program:
sortlist = [32,33,12,44,33,27]
length = len(sortlist)-1
for j in range(0 , length):
for i in range(0 , length):
if sortlist[i] > sortlist[i+1]:
sortlist[i] , sortlist[i+1] = sortlist[i+1] , sortlist[i]
print("During sorting" , sortlist)
length = length-1
print( "After sorted" , sortlist)
Program Output:
***********************************************************************************
0 Comments