fork download
  1. def insertsort( arr ):
  2.  
  3. n = len( arr )
  4.  
  5. for i in range(1, n):
  6.  
  7. temp = arr[i]
  8.  
  9. j = i - 1
  10.  
  11. while j >= 0 and arr[j] > temp:
  12.  
  13. arr[j+1] = arr[j]
  14.  
  15. j -= 1
  16.  
  17. arr[j+1] = temp
  18.  
  19.  
  20. def main():
  21.  
  22. arr = [9,8,7,6,5]
  23.  
  24. print(arr)
  25.  
  26. insertsort(arr)
  27.  
  28. print(arr)
  29.  
  30. main()
  31.  
Success #stdin #stdout 0.02s 9128KB
stdin
Standard input is empty
stdout
[9, 8, 7, 6, 5]
[5, 6, 7, 8, 9]