Skip to content

Commit fe86d67

Browse files
authored
Merge pull request argonautica#35 from monkfromearth/monkfromearth
Add Insertion Sort in Python
2 parents f06342f + 3baf9b9 commit fe86d67

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Python/InsertionSort.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def InsertionSort(List):
2+
for i in range(1, len(List)):
3+
key = List[i]
4+
j = i - 1
5+
while j >= 0 and key < List[j]:
6+
List[j + 1] = List[j]
7+
j -= 1
8+
List[j + 1] = key
9+
print('The sorted list: \t', List)
10+
11+
if __name__ == "__main__":
12+
lst = []
13+
size = int(input("\nEnter size of the list: \t"))
14+
for i in range(size):
15+
elements = int(input("Enter the element: \t"))
16+
lst.append(elements)
17+
InsertionSort(lst)

0 commit comments

Comments
 (0)