import random def quickSort(L, low=0, high=None): i = low if high: j = high else: j = len(L)-1 if i >= j: return L key = L[i] while i < j: while i < j and L[j] >= key: j = j-1 L[i] = L[j] while i < j and L[i] <= key: i = i+1 L[j] = L[i] L[i] = key quickSort(L, low, i-1) quickSort(L, j+1, high) return L L = [] for i in range(10): L.append(int(random.random()*10000)) print L quickSort(L)
网上现成的快排算法,我稍微改了一下,但是运行的时候怎么就报错。我感觉没毛病啊。
File "/Users/apple/workspace/crypto/crypto/quick_sort.py", line 20, in quickSort
quickSort(L, low, i-1)
File "/Users/apple/workspace/crypto/crypto/quick_sort.py", line 20, in quickSort
quickSort(L, low, i-1)
File "/Users/apple/workspace/crypto/crypto/quick_sort.py", line 20, in quickSort
quickSort(L, low, i-1)
File "/Users/apple/workspace/crypto/crypto/quick_sort.py", line 20, in quickSort
quickSort(L, low, i-1)
RuntimeError: maximum recursion depth exceeded
时好时不好,超过python递归深度限制了?
孤独的小猪
凌舞青春
相关分类