MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / merge

Function merge

sorts/iterative_merge_sort.py:15–25  ·  view source on GitHub ↗

sorting left-half and right-half individually then merging them into result

(input_list: list, low: int, mid: int, high: int)

Source from the content-addressed store, hash-verified

13
14
15def merge(input_list: list, low: int, mid: int, high: int) -> list:
16 """
17 sorting left-half and right-half individually
18 then merging them into result
19 """
20 result = []
21 left, right = input_list[low:mid], input_list[mid : high + 1]
22 while left and right:
23 result.append((left if left[0] <= right[0] else right).pop(0))
24 input_list[low : high + 1] = result + left + right
25 return input_list
26
27
28# iteration over the unsorted list

Callers 1

iter_merge_sortFunction · 0.70

Calls 2

appendMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected