Commit 93844478 authored by 高雅喆's avatar 高雅喆

update

parent 08e45a4e
def merge_sort(lst):
if len(lst) <= 1:
return lst
middle = int(len(lst) / 2)
left = merge_sort(lst[:middle])
right = merge_sort(lst[middle:])
merged = []
while left and right:
merged.append(left.pop(0) if left[0] <= right[0] else right.pop(0))
merged.extend(right if right else left)
return merged
data_lst = [6,202,100,301,38,8,1]
print(merge_sort(data_lst))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment