8000 Merge pull request #7 from Bharat-Reddy/master · AllAlgorithms/python@f3f3484 · GitHub
[go: up one dir, main page]

Skip to content

Commit f3f3484

Browse files
authored
Merge pull request #7 from Bharat-Reddy/master
Insertion Sort Added
2 parents b80a3e6 + 81ce442 commit f3f3484

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

sorting/insertion_sort.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Python program for implementation of Insertion Sort
2+
3+
# Function to do insertion sort
4+
def insertionSort(arr):
5+
6+
7+
for i in range(1, len(arr)):
8+
9+
key = arr[i]
10+
11+
j = i-1
12+
while j >=0 and key < arr[j] :
13+
arr[j+1] = arr[j]
14+
j -= 1
15+
arr[j+1] = key
16+
17+
18+
arr = [12, 11, 13, 5, 6]
19+
insertionSort(arr)
20+
for i in range(len(arr)):
21+
print ("%d" %arr[i])

0 commit comments

Comments
 (0)
0