排序
快速排序
基于辅助数组实现的快速排序
from random import randint
# 借助额外数组,容易理解
def quick_sort_with_help(nums: list) -> list:
if len(nums) <= 1:
return nums
rd = randint(0, len(nums) - 1)
low = list()
mid = list()
high = list()
for a in nums:
if a < nums[rd]:
low.append(a)
elif a > nums[rd]:
high.append(a)
else:
mid.append(a)
low = quick_sort_with_help(low)
high = quick_sort_with_help(high)
low.extend(mid)
low.extend(high)
return low基于双指针实现的快速排序
python实现
go实现
归并排序
基于分治实现的归并排序
python实现
go实现
python3实现
go实现
最后更新于