Answers for "explain the python implementation of an insertion sort."

-7

insertion sort in python

def insertion(s):
    for i in range(0,len(s)-1):
        if s[i]>s[i+1]:
            s[i],s[i+1]=s[i+1],s[i]
            for j in range(i,0,-1):
                if s[j]<s[j-1]:
                    s[j],s[j-1]=s[j-1],s[j]
    print(s)
    
insertion([5,2,1,9,0,4,6])
Posted by: Guest on March-01-2021

Python Answers by Framework

Browse Popular Code Answers by Language