fork download
  1. my_array = [64, 34, 25, 12, 22, 11, 90, 5]
  2.  
  3. n = len(my_array)
  4. for i in range(1,n):
  5. insert_index = i
  6. current_value = my_array[i]
  7. for j in range(i-1, -1, -1):
  8. if my_array[j] > current_value:
  9. my_array[j+1] = my_array[j]
  10. insert_index = j
  11. else:
  12. break
  13. my_array[insert_index] = current_value
  14.  
  15. print("Sorted array:", my_array)
Success #stdin #stdout 0.04s 9616KB
stdin
Standard input is empty
stdout
Sorted array: [5, 11, 12, 22, 25, 34, 64, 90]