Monday 2 January 2017

What is Bubble sort?

 It compares adjacent items and exchanges those that are out of order.

Example:
x=[47, 98, 85, 85, 67, 67]
def bubble_sort(x):
for i in range(len(x)-1,0,-1):
for j in range(i):
if x[j]>x[j+1]:
temp=x[j]
x[j]=x[j+1]
x[j+1]=temp
return x

>>> print(bubble_sort(x))
[47, 67, 67, 85, 85, 98]