Friday, November 13, 2015

insertion sort in Python

def insertion(A):
x=1
while(x<len(A)):

key=A[x]
i=x-1
while (i>=0)and (A[i]>key):
A[i+1]=A[i]
i=i-1
A[i+1]=key
x+=1
a=[3,2,1,4]
insertion(a)


No comments:

Post a Comment

Contributors

Translate