Python随笔-快排
2021-05-19 03:27
标签:wap turn end col temp div 快排 span code Python随笔-快排 标签:wap turn end col temp div 快排 span code 原文地址:https://www.cnblogs.com/wrbxdj/p/9378678.htmldef swap(arr, i, j):
temp = arr[i]
arr[i] = arr[j]
arr[j] = temp
def part(arr, beg, end):
if end - beg 0:
return beg
v = arr[beg]
idx = beg + 1
for x in range(beg+1, end+1):
if(arr[x] v):
swap(arr, idx, x)
idx += 1
swap(arr, idx-1, beg)
return idx-1
def sort(arr, beg, end):
if end - beg 0:
return
i = part(arr, beg, end)
sort(arr, beg, i)
sort(arr, i+1, end)
arr = [5, 10, 6, 7, 1, 2, 3, 0, 3, 10, 99, 22, 33, 23, 45]
sort(arr, 0, len(arr)-1)
print(arr)