标签:sort turn app __name__ ret name pen lis lse
def half_sort(test_list):
half = len(test_list) // 2
if len(test_list)<=1:
return test_list
right_list = half_sort(test_list[:half])
left_list = half_sort(test_list[half:])
right_index, left_index = 0, 0
add_list = []
while right_index<len(right_list) and left_index < len(left_list):
if right_list[right_index] < left_list[left_index]:
add_list.append(right_list[right_index] )
right_index += 1
else:
add_list.append(left_list[left_index])
left_index += 1
add_list += right_list[right_index:]
add_list += left_list[left_index:]
return add_list
def main():
print(half_sort(test_list))
if __name__ == ‘__main__‘:
main()
标签:sort turn app __name__ ret name pen lis lse
原文地址:https://www.cnblogs.com/guducp/p/9154792.html