Quick actions

cmd+k|ctrl+k

Navigation

Languages

insertion sort

Snippet info

Language

Python

Visibility

public

Author

sriram

Created

2025-04-28T06:00:45.625912Z

Updated

2025-04-28T06:00:45.625912Z

def insertion_sort(a):
    for i in range(1, len(a)):
        key = a[i]
        j = i - 1
        while j >= 0 and a[j] > key:
            a[j + 1] = a[j]
            j -= 1
        a[j + 1] = key

a = [9, 5, 1, 4, 3]
insertion_sort(a)
print(a)
INFO