Skip to content

Commit cf72c29

Browse files
committed
Sorting
1 parent 0d1297d commit cf72c29

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

sorting/InsertionSort.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def insertionsort(A):
2+
n = len(A)
3+
for i in range(1,n):
4+
cvalue = A[i]
5+
position = i
6+
while position > 0 and A[position-1] > cvalue:
7+
A[position] = A[position-1]
8+
position = position - 1
9+
A[position] = cvalue
10+
11+
12+
A = [3,5,8,9,6,2]
13+
print('Original Array:',A)
14+
insertionsort(A)
15+
print('Sorted Array:',A)

0 commit comments

Comments
 (0)