快速排序
2020-12-19 17:40
标签:odi 溢出 while span dom range mit sort shuff 快速排序 才发现自己配置好差,最坏情况10000就堆栈溢出了。。。。。 快速排序 标签:odi 溢出 while span dom range mit sort shuff 原文地址:https://www.cnblogs.com/Bethuel/p/13378123.html# coding: utf-8
import random
import sys
sys.setrecursionlimit(100000000)
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)
return li
def partition(li, left, right):
tmp = li[left]
while left right:
while left and li[right] >= tmp:
right -= 1
li[left] = li[right]
while left and li[left] tmp:
left += 1
li[right] = li[left]
li[right] = tmp
return left
li = list(range(10000,0,-1))
random.shuffle(li)
print(quick_sort(li,0,len(li)-1))