implements insertion sort in c and pytyhon
This commit is contained in:
13
python/insertion-sort.py
Normal file
13
python/insertion-sort.py
Normal file
@@ -0,0 +1,13 @@
|
||||
def insertion_sort(array):
|
||||
for index in range(1, len(array)):
|
||||
temp_value = array[index]
|
||||
position = index - 1
|
||||
|
||||
while position >= 0:
|
||||
if array[position] > temp_value:
|
||||
array[position + 1] = array[position]
|
||||
else:
|
||||
break
|
||||
array[position + 1] = temp_value
|
||||
|
||||
return array
|
||||
Reference in New Issue
Block a user