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
19 changes: 19 additions & 0 deletions InsertionSort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def InSort(ar):
#Assuming first element is sorted
#start on second element
for i in range(1, len(ar)):
ins = ar[i]
#Save the previous value
j = i-1
#Move all the sorted larger elements ahead
while j>=0 and ar[j] > ins:
ar[j+1] = ar[j]
j = j-1
#Make insertion XD
ar[j+1] = ins

return ar

#Print
print(InSort([5,6,8,9,2,3,66,45,1,25,00,-1]))