Skip to content

Commit 94f876c

Browse files
committed
feat: add insertion sort
1 parent 389b4b3 commit 94f876c

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎Sorting/insertion_sort.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def insertion_sort(arr):
2+
n = len(arr)
3+
4+
for i in range(1, n):
5+
key = arr[i]
6+
j = i - 1
7+
8+
while j >= 0 and arr[j] > key:
9+
arr[j + 1] = arr[j]
10+
j -= 1
11+
12+
arr[j + 1] = key
13+
14+
return arr
15+
16+
print(insertion_sort([23,5,98,56,69,2]))

0 commit comments

Comments
 (0)