0
私は再帰関数には、次のクイックソートのコードでは、再帰の最も深いレベル、すなわち、下降どれだけ見つけるためにしようとしています
、私は、qソート機能を編集することが言われているし、任意の助けをいただければ幸いですPythonのクイックソートは再帰的な深さ
def partition(lst, lo, hi):
part = lo
while lo < hi:
while lst[lo] <= lst[part] and lo < hi:
lo += 1
while lst[hi] > lst[part]: # Don't have to check for hi >= 0 cos part is there as a sentinel.
hi -= 1
if lo < hi:
# Swap the two entries
lst[hi], lst[lo] = lst[lo], lst[hi]
# Swap part into position
if lst[part] > lst[hi]: # (this may happen of the array is small (size 2))
lst[part], lst[hi] = lst[hi], lst[part]
print(part)
return hi
def rec_qsort(lst, lo, hi):
if lo < hi:
pivot = partition(lst, lo, hi)
rec_qsort(lst, lo, pivot - 1)
rec_qsort(lst, pivot + 1, hi)
def qsort(lst):
rec_qsort(lst, 0, len(lst) - 1)
return lst
'qsort'から何も返されていません。 –
が修正されました。リスト自体には興味がありませんが、qsort関数の再帰的な深さには興味がありません。 – Alex