Skip to content

Commit f8f8ab9

Browse files
committedMay 18, 2022
insertion sorting algorithm
1 parent 231d3bc commit f8f8ab9

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
 

‎algorithms/app2.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
if f == True:
1212
l[i], l[min] = l[min], l[i]
1313
print(l)
14-
14+
15+
print("Sorted list: ", l)

‎algorithms/app3.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Insertion sorting
2+
l = eval(input("Enter your number list: "))
3+
n = len(l)
4+
for i in range(n):
5+
t = l[i]
6+
k = i - 1
7+
while k >=0 and l[k] > t:
8+
l[k + 1] = l[k]
9+
k = k- 1
10+
l[k + 1] = t
11+
print(l)
12+
13+
print("Sorted list: ", l)

0 commit comments

Comments
 (0)
Please sign in to comment.