Pages

Tuesday, 19 January 2016

Bubble Sort in Python 2.7

def bubble_sort(L) :
    for j in range(len(L)-1) :
        print "------ Iteration",j+1,"------"
        for i in range(len(L)-1) :
            if L[i]>L[i+1] :
                a=L[i+1]
                L[i+1]=L[i]
                L[i]=a
            print "List after pass",i+1,":",L