Day 2 Sorting Algo Practice | Insertion Sort

admin
By -
0 minute read
0


arr = [42, 17, 93, 58, 26, 71, 11, 39, 84, 6]

#Insetrtion sort

n = len(arr)

def in_sort(arr):

    for i in range(1,n):

        temp = arr[i]

        j = i -1

        while j  >=0 and temp < arr[j]:

            arr[j+1] = arr[j]

            j = j - 1

            

        arr[j+1] = temp

    print(arr)

    

in_sort(arr)

Post a Comment

0Comments

Today | 8, April 2025