Skip to content

Commit fe0db18

Browse files
committed
InsertionSort.py finally approved
1 parent c3f47d4 commit fe0db18

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#Insertion Sort
2+
3+
def insertion_sort(unsorted_list):
4+
for i in range(1, len(unsorted_list)):
5+
search_index = i
6+
insert_value = unsorted_list[i]
7+
while search_index > 0 and unsorted_list[search_index - 1] > insert_value:
8+
unsorted_list[search_index] = unsorted_list[search_index - 1]
9+
search_index -= 1
10+
unsorted_list[search_index] = insert_value
11+
12+
13+
print("-----Insertion Sort Outputs-----\n")
14+
my_list = [5, 1, 100, 2, 10]
15+
print("Original list", my_list)
16+
insertion_sort(my_list)
17+
print("Sorted list", my_list)

0 commit comments

Comments
 (0)