python的归并排序怎么写
时间: 2023-02-19 21:03:33 浏览: 80
归并排序Python版的
归并排序的Python实现如下:
def merge_sort(arr):
if len(arr) >1:
mid = len(arr)//2 #Finding the mid of the array
L = arr[:mid] # Dividing the array elements
R = arr[mid:] # into 2 halves
merge_sort(L) # Sorting the first half
merge_sort(R) # Sorting the second half
i = j = k = 0
阅读全文