# insertionsort() function to implement insertion sort def insertionsort( aList ): for i in range( 1, len( aList ) ): tmp = aList[i] k = i while k > 0 and tmp < aList[k - 1]: aList[k] = aList[k - 1] k -= 1 aList[k] = tmp # Example to sort an array using insertion sort A=[44,21,3,88,12,65,4] # Calling insertionsort() function insertionsort(A) # printing the sorted array print A
0 comments:
Post a Comment