10000 Insertion Sort · aworleo/programminginpython.com@32f93ca · GitHub
[go: up one dir, main page]

Skip to content

Commit 32f93ca

Browse files
committed
Insertion Sort
1 parent 30f6b2d commit 32f93ca

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
__author__ = 'Avinash'
2+
3+
4+
def insertion_sort(sort_list):
5+
for i in range(1, len(sort_list)):
6+
key = sort_list[i]
7+
j = i - 1
8+
while j >= 0 and key < sort_list[j]:
9+
sort_list[j + 1] = sort_list[j]
10+
j -= 1
11+
sort_list[j + 1] = key
12+
print('\nThe sorted list: \t', sort_list)
13+
print('\n')
14+
15+
16+
lst = []
17+
size = int(input("\nEnter size of the list: \t"))
18+
19+
for i in range(size):
20+
elements = int(input("Enter the element: \t"))
21+
lst.append(elements)
22+
23+
insertion_sort(lst)

0 commit comments

Comments
 (0)
0