Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Insertion sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#List taken from the user and sorted using insertion sort.

print("Enter the list you want to sort(with spaces)")
l=list(map(int,input().split()))
n=len(l)
print("The list you entered: ",l)

for i in range(1,n):
value = l[i]
pos=i
while pos>0 and value<l[pos-1]:
l[pos]=l[pos-1]
pos=pos-1
l[pos]=value
print("The sorted list: ",l)