Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Commit 0c5e282

Browse files
committed
adding the insertionsort.py
Signed-off-by: Kinshuk2003 <[email protected]>
1 parent 2ef9c68 commit 0c5e282

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

contributors/Kinshuk2003-2.md

Lines changed: 0 additions & 1 deletion
This file was deleted.
File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#links to gist
1+
# links to gist
22

33
1. [software development topic](https://gist.github.com/Kinshuk2003/4cea2ff56db2b4da9f26e36f6b11bfee)
4-
2. [Code snippet](https://gist.github.com/Kinshuk2003/ee923b2feaf424367d34e9eae452ec86)
4+
2. [Code snippet](https://gist.github.com/Kinshuk2003/ee923b2feaf424367d34e9eae452ec86)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
5+
def InsertionSort(arr):
6+
7+
n = len(arr)
8+
9+
for i in range(0, n):
10+
key = arr[i]
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+
# driver code
19+
20+
arr = [6, 5, 3, 2, 8, 10, 9]
21+
InsertionSort(arr)
22+
print(arr)

0 commit comments

Comments
 (0)