4
4
5
5
from typing import List
6
6
7
+
7
8
def rec_insertion_sort (collection : List , n : int ):
8
9
"""
9
10
Given a collection of numbers and its length, sorts the collections
@@ -27,13 +28,13 @@ def rec_insertion_sort(collection: List, n: int):
27
28
>>> print(col)
28
29
[1]
29
30
"""
30
- #Checks if the entire collection has been sorted
31
+ # Checks if the entire collection has been sorted
31
32
if len (collection ) <= 1 or n <= 1 :
32
33
return
33
34
35
+ insert_next (collection , n - 1 )
36
+ rec_insertion_sort (collection , n - 1 )
34
37
35
- insert_next (collection , n - 1 )
36
- rec_insertion_sort (collection , n - 1 )
37
38
38
39
def insert_next (collection : List , index : int ):
39
40
"""
@@ -54,17 +55,19 @@ def insert_next(collection: List, index: int):
54
55
>>> print(col)
55
56
[]
56
57
"""
57
- #Checks order between adjacent elements
58
+ # Checks order between adjacent elements
58
59
if index >= len (collection ) or collection [index - 1 ] <= collection [index ]:
59
60
return
60
61
61
- #Swaps adjacent elements since they are not in ascending order
62
+ # Swaps adjacent elements since they are not in ascending order
62
63
collection [index - 1 ], collection [index ] = (
63
- collection [index ], collection [index - 1 ]
64
+ collection [index ],
65
+ collection [index - 1 ],
64
66
)
65
67
66
68
insert_next (collection , index + 1 )
67
69
70
+
68
71
if __name__ == "__main__" :
69
72
numbers = input ("Enter integers seperated by spaces: " )
70
73
numbers = [int (num ) for num in numbers .split ()]
0 commit comments