insertion sort

PHOTO EMBED

Tue May 07 2024 07:59:26 GMT+0000 (Coordinated Universal Time)

Saved by @jass855 #python

n=int(input('total number of items in list'))
L=[]
for i in range(n):
    item=int(input('enter the item'))
    L.append(item)
n=int(input('total number of items in list'))
L=[]
for i in range(n):
    item=int(input('enter the item'))
    L.append(item)



for i in range(1,n):
    k=L[i]
    j=i-1
    while j>=0 and k<L[j]:
        L[j+1]=L[j]
        j=j-1
    else:
        L[j+1]=k
print('sorted list:\n',L)

content_copyCOPY