File tree Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -40,13 +40,12 @@ def insertion_sort(collection: list) -> list:
40
40
True
41
41
"""
42
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 ]
43
+ for insert_index in range ( 1 , len ( collection ) ):
44
+ insert_value = collection [ insert_index ]
45
+ while insert_index > 0 and insert_value < collection [insert_index - 1 ]:
46
+ collection [insert_index ] = collection [insert_index - 1 ]
47
47
insert_index -= 1
48
- if insert_index != temp_index :
49
- collection [insert_index + 1 ] = insert_value
48
+ collection [insert_index ] = insert_value
50
49
return collection
51
50
52
51
You can’t perform that action at this time.
0 commit comments