Skip to content

Latest commit

 

History

History
21 lines (15 loc) · 464 Bytes

insertion sort in python.md

File metadata and controls

21 lines (15 loc) · 464 Bytes

Python program for implementation of Insertion Sort

Function to do insertion sort

def insertionSort(nlist):
   for index in range(1,len(nlist)):

     currentvalue = nlist[index]
     position = index

     while position>0 and nlist[position-1]>currentvalue:
         nlist[position]=nlist[position-1]
         position = position-1

     nlist[position]=currentvalue

nlist = [14,46,43,27,57,41,45,21,70]
insertionSort(nlist)
print(nlist)