We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1210559 commit c227ff9Copy full SHA for c227ff9
sorts/insertion_sort.py
@@ -40,13 +40,12 @@ def insertion_sort(collection: list) -> list:
40
True
41
"""
42
43
- for insert_index, insert_value in enumerate(collection[1:]):
44
- temp_index = insert_index
45
- while insert_index >= 0 and insert_value < collection[insert_index]:
46
- collection[insert_index + 1] = collection[insert_index]
+ for insert_index in range(1, len(collection)):
+ insert_value = collection[insert_index]
+ while insert_index > 0 and insert_value < collection[insert_index - 1]:
+ collection[insert_index] = collection[insert_index - 1]
47
insert_index -= 1
48
- if insert_index != temp_index:
49
- collection[insert_index + 1] = insert_value
+ collection[insert_index] = insert_value
50
return collection
51
52
0 commit comments