Repository where I mostly put random python scripts.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
416 B

5 years ago
  1. # coding: utf-8
  2. # In[55]:
  3. alist = [54,26,93,17,77,31,44,55,20]
  4. def insertionSort(alist):
  5. for index in range(1,len(alist)):
  6. currentvalue = alist[index]
  7. position = index
  8. while position>0 and alist[position-1]>currentvalue:
  9. alist[position]=alist[position-1]
  10. position = position-1
  11. alist[position]=currentvalue
  12. return alist
  13. print(insertionSort(alist))