Optimized Insertion Sort

Instructions:

Use Insertion Sort optimized with shifting to sort the table given below in ascending order. Click on an item to select it and copy its value to another position by clicking on the new position.

  1. def inssortshift(A):
  2. for i in range(1, len(A)): # Insert i'th record
  3. temp = A[i]
  4. j=i
  5. while (j > 0) and (temp < A[j-1]):
  6. A[j] = A[j-1]
  7. j -= 1
  8. A[j] = temp

Table to be sorted

  1. 290
  2. 211
  3. 792
  4. 733
  5. 894
  6. 745
  7. 966
  8. 657
  9. 488
  10. 849

temp variable

  1. 60