Advertisement
kananmahammadli

insertion sort

May 27th, 2019
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.31 KB | None | 0 0
  1. def insertion_sort(ls):
  2.     for i in range(1,len(ls)-1):
  3.         value = ls[i]
  4.         j= i
  5.         while j > 0 and ls[j-1]  > value:
  6.             ls[j]=ls[j-1]
  7.             j=j-1
  8.         ls[j]=value
  9.     return ls
  10. from random import*
  11. ls=[randint(0,100) for _ in range(10)]
  12. print(*ls)
  13. print(*insertion_sort(ls))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement