Java版
Java版代码:https://blog.csdn.net/m0_60370702/article/details/123417783?spm=1001.2014.3001.5501
快速排序
li = [i for i in range(1, 5000000)]
random.shuffle(li)
def quick_sort(li, left, right):
if left < right:
mid = partition(li, left, right)
quick_sort(li, left, mid - 1)
quick_sort(li, mid + 1, right)
def partition(li, left, right):
tmp = li[left]
while left < right:
while left < right and li[right] >= tmp:
right -= 1
li[left] = li[right]
while left < right and li[left] <= tmp:
left += 1
li[right] = li[left]
li[left] = tmp
return left
quick_sort(li, 0, len(li) - 1)
print(li)
归并排序
li =