Skip to content

Commit 0f6322d

Browse files
Create insertalgo.py
1 parent 6cd3760 commit 0f6322d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

insertalgo.py

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

0 commit comments

Comments
 (0)