55from __future__ import annotations
66
77from collections .abc import MutableSequence
8- from typing import Any , Protocol , TypeVar
8+ from typing import Protocol
99
1010
1111class Comparable (Protocol ):
12- def __lt__ (self , other : Any , / ) -> bool : ...
12+ def __lt__ (self , other : object , / ) -> bool : ...
1313
1414
15- T = TypeVar ("T" , bound = Comparable )
16-
17-
18- def rec_insertion_sort [T ](collection : MutableSequence [T ], n : int ) -> None :
15+ def rec_insertion_sort [T : Comparable ](collection : MutableSequence [T ], n : int ) -> None :
1916 """
2017 Given a collection of comparable elements and its length, sorts the
2118 collection in place in ascending order.
@@ -51,7 +48,7 @@ def rec_insertion_sort[T](collection: MutableSequence[T], n: int) -> None:
5148 rec_insertion_sort (collection , n - 1 )
5249
5350
54- def insert_next [T ](collection : MutableSequence [T ], index : int ) -> None :
51+ def insert_next [T : Comparable ](collection : MutableSequence [T ], index : int ) -> None :
5552 """
5653 Inserts the '(index-1)th' element into place
5754
@@ -71,7 +68,7 @@ def insert_next[T](collection: MutableSequence[T], index: int) -> None:
7168 []
7269 """
7370 # Checks order between adjacent elements
74- if index >= len (collection ) or collection [index - 1 ] <= collection [index ]:
71+ if index >= len (collection ) or not collection [index ] < collection [index - 1 ]:
7572 return
7673
7774 # Swaps adjacent elements since they are not in ascending order
0 commit comments