MCPcopy Create free account
hub / github.com/geekcomputers/Python / merge_sort

Function merge_sort

Sorting Algorithms/merge_sort.py:36–49  ·  view source on GitHub ↗
(nums)

Source from the content-addressed store, hash-verified

34
35
36def merge_sort(nums):
37 # If the list is a single element, return it
38 if len(nums) <= 1:
39 return nums
40
41 # Use floor division to get midpoint, indices must be integers
42 mid = len(nums) // 2
43
44 # Sort and merge each half
45 left_list = merge_sort(nums[:mid])
46 right_list = merge_sort(nums[mid:])
47
48 # Merge the sorted lists into a new one
49 return merge(left_list, right_list)
50
51
52# Verify it works

Callers 1

merge_sort.pyFile · 0.70

Calls 1

mergeFunction · 0.70

Tested by

no test coverage detected