m2skills

insertion py

Apr 4th, 2017
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. def insertionSort(myList):
  2.     for i in range(0, len(myList)):
  3.         j = i
  4.         while j > 0 and myList[j-1] > myList[j]:
  5.             myList[j] , myList[j-1] = myList[j-1], myList[j]
  6.             j -= 1
  7.     return myList
  8.  
  9. # main function
  10. print("Enter the array to be sorted : ")
  11. myList1 = list(map(int, input().strip().split(",")))
  12.  
  13. myList1 = insertionSort(myList1)
  14. print("The List after applying Bubble Sort is : ")
  15. print(myList1)
Add Comment
Please, Sign In to add comment