def partition(low, high, arr):
index = low - 1
mid = arr[high]
for i in range(low, high + 1):
if arr[i] < mid:
index += 1
arr[i], arr[index] = arr[index], arr[i]
index += 1
arr[index], arr[high] = arr[high], arr[index]
return index
def quick_sort(low, high, arr):
if low < high:
p = partition(low, high, arr)
quick_sort(low, p - 1, arr)
quick_sort(p + 1, high, arr)
index = low - 1
mid = arr[high]
for i in range(low, high + 1):
if arr[i] < mid:
index += 1
arr[i], arr[index] = arr[index], arr[i]
index += 1
arr[index], arr[high] = arr[high], arr[index]
return index
def quick_sort(low, high, arr):
if low < high:
p = partition(low, high, arr)
quick_sort(low, p - 1, arr)
quick_sort(p + 1, high, arr)
全部评论
相关推荐
11-27 20:53
门头沟学院 C++ 拿到offer以后我就:先在年前完成大论文并且好好准备考公,年后提前到公司实习,偷项目丰富简历准备春招并继续考公,最后在几个ssp和公务员中幸福的纠结
点赞 评论 收藏
分享