十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
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))