Insertion sort

Insertion sort full python program with explanation

Hey internet mates here we are going to make a python program to sort a list using insertion method.

Program code:-
li=[]
for x in range (0,10):
    inp=int(input("Enter no.:-"))
    li.append(inp)
print("Original list is:-",li)
for y in range(1,len(li)):
    req=li[y]
    i=y-1
    while i>=0 and req< li[i]:
        li[i+1]=li[i]
        i=i-1
    else:
        li[i+1]=req
print("List after sorting:-",li)

Leave a Comment

Your email address will not be published. Required fields are marked *