Skip to content
Snippets Groups Projects
Commit fa27a910 authored by nilsl99's avatar nilsl99
Browse files

Implemented InsertionSort

parent d953224f
No related branches found
No related tags found
No related merge requests found
......@@ -28,7 +28,16 @@ def InsertionSort(array):
sorted_array: a sorted copy of the array
'''
return
sorted_array = list(array)
for i in range(1, len(array)):
for j in range(i, 1, -1):
if sorted_array[j] < sorted_array[j-1]:
sorted_array[j], sorted_array[j-1] = sorted_array[j-1], sorted_array[j]
else:
continue
return sorted_array
def CountingSort(array):
'''Sort the array by counting the occurrence of each element in the array.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment