MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / insertion_sort

Function insertion_sort

sorts/tim_sort.py:19–27  ·  view source on GitHub ↗
(lst: list[Any])

Source from the content-addressed store, hash-verified

17
18
19def insertion_sort(lst: list[Any]) -> list[Any]:
20 length = len(lst)
21
22 for index in range(1, length):
23 value = lst[index]
24 pos = binary_search(lst, value, 0, index - 1)
25 lst = [*lst[:pos], value, *lst[pos:index], *lst[index + 1 :]]
26
27 return lst
28
29
30def merge(left: list[Any], right: list[Any]) -> list[Any]:

Callers 1

tim_sortFunction · 0.70

Calls 1

binary_searchFunction · 0.70

Tested by

no test coverage detected