Search Program on this blog

Sunday 23 August 2015

Insertion Sort in Python

def sort(c):
        for i in range(0,len(c),1):
                j=i
                while(j>0):
                        if(c[j]<c[j-1]):
                                c[j],c[j-1]=c[j-1],c[j]
                        j-=j 
        return c
                
a=[10,23,54,23,32,98,87]
print a
b=sort(a)
print b

No comments:

Post a Comment