import math
def sort(arr):
num_count = len(arr)
n = 0
while True:
temp_arr = []
group_size = 2 ** n
for i in range(math.ceil(num_count/group_size/2)):
left = arr[group_size*(2*i):group_size*(2*i+1)]
right = arr[group_size*(2*i+1):group_size*(2*i+2)]
while left and right:
if left[0] > right[0]:
temp_arr.append(left.pop(0))
else:
temp_arr.append(right.pop(0))
temp_arr.extend(left)
temp_arr.extend(right)
arr = temp_arr
if group_size >= num_count:
break
n += 1
return arr
la = [5, 2, 7, 8, 6, 1, 4, 9, 10, 1, 2, 3, 4]
print(sort(la))
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。