Skip to content

Commit e66d515

Browse files
committed
added - insSort
1 parent 37d0ae4 commit e66d515

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

insertion-sort/insert.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Sorting Arrays using Insertion Sort Method
2+
3+
def insSort(arr):
4+
n = len(arr)
5+
for i in range(1, n):
6+
key = arr[i]
7+
j = i - 1
8+
while j >= 0 and key < arr[j]:
9+
arr[j + 1] = arr[j]
10+
j -= 1
11+
arr[j + 1] = key
12+
13+
arr = [1, 3, 6, 7, 4, 10]
14+
insSort(arr)
15+
print("Sorted array is:", arr)

0 commit comments

Comments
 (0)