大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
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))